mirror of
https://github.com/mmumshad/ansible-playable.git
synced 2025-03-09 23:38:54 +00:00
Initial Commit
This commit is contained in:
commit
c92f737237
273 changed files with 16964 additions and 0 deletions
31
server/auth/google/passport.js
Normal file
31
server/auth/google/passport.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import passport from 'passport';
|
||||
import {Strategy as GoogleStrategy} from 'passport-google-oauth20';
|
||||
|
||||
export function setup(User, config) {
|
||||
passport.use(new GoogleStrategy({
|
||||
clientID: config.google.clientID,
|
||||
clientSecret: config.google.clientSecret,
|
||||
callbackURL: config.google.callbackURL
|
||||
},
|
||||
function(accessToken, refreshToken, profile, done) {
|
||||
User.findOne({'google.id': profile.id}).exec()
|
||||
.then(user => {
|
||||
if(user) {
|
||||
return done(null, user);
|
||||
}
|
||||
|
||||
user = new User({
|
||||
name: profile.displayName,
|
||||
email: profile.emails[0].value,
|
||||
role: 'user',
|
||||
username: profile.emails[0].value.split('@')[0],
|
||||
provider: 'google',
|
||||
google: profile._json
|
||||
});
|
||||
user.save()
|
||||
.then(savedUser => done(null, savedUser))
|
||||
.catch(err => done(err));
|
||||
})
|
||||
.catch(err => done(err));
|
||||
}));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue