2017-04-11 17:41:14 -04:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const Router = require('express').Router
|
|
|
|
const passport = require('passport')
|
2021-02-15 03:42:51 -05:00
|
|
|
const GoogleStrategy = require('passport-google-oauth20').Strategy
|
2017-04-11 17:41:14 -04:00
|
|
|
const config = require('../../../config')
|
2019-11-28 06:25:59 -05:00
|
|
|
const { passportGeneralCallback } = require('../utils')
|
2017-04-11 17:41:14 -04:00
|
|
|
|
2021-02-15 03:42:51 -05:00
|
|
|
const googleAuth = module.exports = Router()
|
2017-04-11 17:41:14 -04:00
|
|
|
|
|
|
|
passport.use(new GoogleStrategy({
|
|
|
|
clientID: config.google.clientID,
|
|
|
|
clientSecret: config.google.clientSecret,
|
2019-03-09 08:42:06 -05:00
|
|
|
callbackURL: config.serverURL + '/auth/google/callback',
|
2019-05-30 18:27:56 -04:00
|
|
|
userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
|
2017-04-11 17:41:14 -04:00
|
|
|
}, passportGeneralCallback))
|
|
|
|
|
2017-09-04 04:04:20 -04:00
|
|
|
googleAuth.get('/auth/google', function (req, res, next) {
|
2020-02-06 19:51:58 -05:00
|
|
|
passport.authenticate('google', { scope: ['profile'], hostedDomain: config.google.hostedDomain })(req, res, next)
|
2017-04-11 17:41:14 -04:00
|
|
|
})
|
2019-05-30 18:27:56 -04:00
|
|
|
// google auth callback
|
2017-09-04 04:04:20 -04:00
|
|
|
googleAuth.get('/auth/google/callback',
|
2017-04-11 17:41:14 -04:00
|
|
|
passport.authenticate('google', {
|
2018-03-07 09:17:35 -05:00
|
|
|
successReturnToOrRedirect: config.serverURL + '/',
|
|
|
|
failureRedirect: config.serverURL + '/'
|
2017-04-11 17:41:14 -04:00
|
|
|
})
|
|
|
|
)
|