This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
33 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 |
---|---|---|
@@ -1,39 +1,39 @@ | ||
'use strict'; | ||
|
||
var passport = require('passport'), | ||
url = require('url'), | ||
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy, | ||
config = require('../config'), | ||
users = require('../../app/controllers/users.server.controller'); | ||
url = require('url'), | ||
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy, | ||
config = require('../config'), | ||
users = require('../../app/controllers/users.server.controller'); | ||
|
||
module.exports = function() { | ||
// Use google strategy | ||
passport.use(new GoogleStrategy({ | ||
clientID: config.google.clientID, | ||
clientSecret: config.google.clientSecret, | ||
callbackURL: config.google.callbackPath, | ||
passReqToCallback: true | ||
}, | ||
function(req, accessToken, refreshToken, profile, done) { | ||
// Set the provider data and include tokens | ||
var providerData = profile._json; | ||
providerData.accessToken = accessToken; | ||
providerData.refreshToken = refreshToken; | ||
|
||
// Create the user OAuth profile | ||
var providerUserProfile = { | ||
firstName: profile.name.givenName, | ||
lastName: profile.name.familyName, | ||
displayName: profile.displayName, | ||
email: profile.emails[0].value, | ||
username: profile.username, | ||
provider: 'google', | ||
providerIdentifierField: 'id', | ||
providerData: providerData | ||
}; | ||
// Use google strategy | ||
passport.use(new GoogleStrategy({ | ||
clientID: config.google.clientID, | ||
clientSecret: config.google.clientSecret, | ||
callbackURL: config.google.callbackPath, | ||
passReqToCallback: true | ||
}, | ||
function(req, accessToken, refreshToken, profile, done) { | ||
// Set the provider data and include tokens | ||
var providerData = profile._json; | ||
providerData.accessToken = accessToken; | ||
providerData.refreshToken = refreshToken; | ||
|
||
// Save the user OAuth profile | ||
users.saveOAuthUserProfile(req, providerUserProfile, done); | ||
} | ||
)); | ||
}; | ||
// Create the user OAuth profile | ||
var providerUserProfile = { | ||
firstName: profile.name.givenName, | ||
lastName: profile.name.familyName, | ||
displayName: profile.displayName, | ||
email: profile.emails[0].value, | ||
username: profile.username, | ||
provider: 'google', | ||
providerIdentifierField: 'id', | ||
providerData: providerData | ||
}; | ||
|
||
// Save the user OAuth profile | ||
users.saveOAuthUserProfile(req, providerUserProfile, done); | ||
} | ||
)); | ||
}; |