(dbUrl, apiKey, dbName, collection)
| 4 | var rest = require('request'); |
| 5 | |
| 6 | function MongoDBStrategy(dbUrl, apiKey, dbName, collection) { |
| 7 | this.dbUrl = dbUrl; |
| 8 | this.apiKey = apiKey; |
| 9 | this.dbName = dbName; |
| 10 | this.collection = collection; |
| 11 | this.baseUrl = this.dbUrl + '/databases/' + this.dbName + '/collections/' + collection + '/'; |
| 12 | |
| 13 | // Call the super constructor - passing in our user verification function |
| 14 | // We use the email field for the username |
| 15 | LocalStrategy.call(this, { usernameField: 'email' }, this.verifyUser.bind(this)); |
| 16 | |
| 17 | // Serialize the user into a string (id) for storing in the session |
| 18 | passport.serializeUser(function(user, done) { |
| 19 | done(null, user._id.$oid); // Remember that MongoDB has this weird { _id: { $oid: 1234567 } } structure |
| 20 | }); |
| 21 | |
| 22 | // Deserialize the user from a string (id) into a user (via a cll to the DB) |
| 23 | passport.deserializeUser(this.get.bind(this)); |
| 24 | |
| 25 | // We want this strategy to have a nice name for use by passport, e.g. app.post('/login', passport.authenticate('mongo')); |
| 26 | this.name = MongoDBStrategy.name; |
| 27 | } |
| 28 | |
| 29 | // MongoDBStrategy inherits from LocalStrategy |
| 30 | util.inherits(MongoDBStrategy, LocalStrategy); |
nothing calls this directly
no outgoing calls
no test coverage detected