1
0
Fork 0
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:
Mumshad Mannambeth 2017-06-07 13:36:44 -04:00
commit c92f737237
273 changed files with 16964 additions and 0 deletions

View file

@ -0,0 +1,23 @@
'use strict';
import express from 'express';
import passport from 'passport';
import {setTokenCookie} from '../auth.service';
var router = express.Router();
router
.get('/', passport.authenticate('google', {
failureRedirect: '/signup',
scope: [
'profile',
'email'
],
session: false
}))
.get('/callback', passport.authenticate('google', {
failureRedirect: '/signup',
session: false
}), setTokenCookie);
export default router;

View 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));
}));
}