diff --git a/modules/users/server/config/strategies/google.js b/modules/users/server/config/strategies/google.js index f19debcae3..1fc2980ebe 100644 --- a/modules/users/server/config/strategies/google.js +++ b/modules/users/server/config/strategies/google.js @@ -14,30 +14,30 @@ module.exports = function (config) { clientSecret: config.google.clientSecret, callbackURL: config.google.callbackURL, passReqToCallback: true, - scope: [ 'https://www.googleapis.com/auth/userinfo.profile', - 'https://www.googleapis.com/auth/userinfo.email' - ] - }, - function (req, accessToken, refreshToken, profile, done) { - // Set the provider data and include tokens - var providerData = profile._json; - providerData.accessToken = accessToken; - providerData.refreshToken = refreshToken; + scope: ['https://www.googleapis.com/auth/userinfo.profile', + 'https://www.googleapis.com/auth/userinfo.email' + ] + }, + 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, - profileImageURL: (providerData.picture) ? providerData.picture : undefined, - provider: 'google', - providerIdentifierField: 'id', - providerData: providerData - }; + // 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, + profileImageURL: (providerData.picture) ? providerData.picture : undefined, + provider: 'google', + providerIdentifierField: 'id', + providerData: providerData + }; - // Save the user OAuth profile - users.saveOAuthUserProfile(req, providerUserProfile, done); - })); + // Save the user OAuth profile + users.saveOAuthUserProfile(req, providerUserProfile, done); + })); }; diff --git a/modules/users/server/controllers/users/users.authentication.server.controller.js b/modules/users/server/controllers/users/users.authentication.server.controller.js index f3b2008f90..696aee78d0 100644 --- a/modules/users/server/controllers/users/users.authentication.server.controller.js +++ b/modules/users/server/controllers/users/users.authentication.server.controller.js @@ -84,33 +84,33 @@ exports.signout = function (req, res) { * OAuth provider call */ exports.oauthCall = function (req, res, next) { - var strategy = req.params.strategy; - // Authenticate - passport.authenticate(strategy)(req, res, next); - }; + var strategy = req.params.strategy; + // Authenticate + passport.authenticate(strategy)(req, res, next); +}; /** * OAuth callback */ exports.oauthCallback = function (req, res, next) { - var strategy = req.params.strategy; + var strategy = req.params.strategy; - // info.redirect_to contains inteded redirect path - passport.authenticate(strategy, function (err, user, info) { + // info.redirect_to contains inteded redirect path + passport.authenticate(strategy, function (err, user, info) { + if (err) { + return res.redirect('/authentication/signin?err=' + encodeURIComponent(errorHandler.getErrorMessage(err))); + } + if (!user) { + return res.redirect('/authentication/signin'); + } + req.login(user, function (err) { if (err) { - return res.redirect('/authentication/signin?err=' + encodeURIComponent(errorHandler.getErrorMessage(err))); - } - if (!user) { return res.redirect('/authentication/signin'); } - req.login(user, function (err) { - if (err) { - return res.redirect('/authentication/signin'); - } - return res.redirect(info.redirect_to || '/'); - }); - })(req, res, next); + return res.redirect(info.redirect_to || '/'); + }); + })(req, res, next); }; /**