-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use an OAuth providers for authenticating users within your server. - Set up your server using Passport OAuth modules to enable user authentication using OAuth providers.
- Loading branch information
Showing
6 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var passport = require('passport'); | ||
var User = require('./models/user'); | ||
var config = require('./config'); | ||
var LocalStrategy = require('passport-local').Strategy; | ||
var GithubStrategy = require('passport-github').Strategy; | ||
|
||
exports.local = passport.use(new LocalStrategy(User.authenticate())); | ||
passport.serializeUser(User.serializeUser()); | ||
passport.deserializeUser(User.deserializeUser()); | ||
|
||
exports.github = passport.use(new GithubStrategy({ | ||
clientID: config.github.clientID, | ||
clientSecret: config.github.clientSecret, | ||
callbackURL: config.github.callbackURL | ||
}, | ||
function (accessToken, refreshToken, profile, done) { | ||
User.findOne({OauthId: profile.id}, function (err, user) { | ||
if (err) { | ||
console.log(err); // handle errors! | ||
} | ||
if (!err && user !== null) { | ||
done(null, user); | ||
} else { | ||
user = new User({ | ||
username: profile.displayName | ||
}); | ||
user.OauthId = profile.id; | ||
user.OauthToken = accessToken; | ||
user.save(function (err) { | ||
if (err) { | ||
console.log(err); // handle errors! | ||
} else { | ||
console.log("saving user ..."); | ||
done(null, user); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
module.exports = { | ||
'secretKey': 'http://jennica.space', | ||
'mongoUrl': 'mongodb://localhost:27017/conFusion' | ||
'mongoUrl': 'mongodb://localhost:27017/conFusion', | ||
'github': { | ||
clientID: '7cde94e0406e8531304e', | ||
clientSecret: 'af4814dbfcee082e0d62e2ceb5f0ddef9bd5b5c0', | ||
callbackURL: 'https://localhost:3443/users/github/callback' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters