2017-04-11 21:41:14 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const Router = require('express').Router
|
|
|
|
const passport = require('passport')
|
|
|
|
var GoogleStrategy = require('passport-google-oauth20').Strategy
|
2020-01-04 22:30:23 +00:00
|
|
|
const config = require('../../config')
|
2019-04-12 09:58:06 +00:00
|
|
|
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
|
2017-04-11 21:41:14 +00:00
|
|
|
|
2019-08-01 16:59:10 +00:00
|
|
|
const googleAuth = module.exports = Router()
|
2017-04-11 21:41:14 +00:00
|
|
|
|
|
|
|
passport.use(new GoogleStrategy({
|
|
|
|
clientID: config.google.clientID,
|
|
|
|
clientSecret: config.google.clientSecret,
|
2019-03-09 13:42:06 +00:00
|
|
|
callbackURL: config.serverURL + '/auth/google/callback',
|
2019-04-12 09:58:06 +00:00
|
|
|
userProfileURL: 'https://www.googleapis.com/oauth2/v3/userinfo'
|
2017-04-11 21:41:14 +00:00
|
|
|
}, passportGeneralCallback))
|
|
|
|
|
2017-09-04 08:04:20 +00:00
|
|
|
googleAuth.get('/auth/google', function (req, res, next) {
|
2017-04-11 21:41:14 +00:00
|
|
|
setReturnToFromReferer(req)
|
|
|
|
passport.authenticate('google', { scope: ['profile'] })(req, res, next)
|
|
|
|
})
|
2019-04-12 09:58:06 +00:00
|
|
|
// google auth callback
|
2017-09-04 08:04:20 +00:00
|
|
|
googleAuth.get('/auth/google/callback',
|
2017-04-11 21:41:14 +00:00
|
|
|
passport.authenticate('google', {
|
2018-03-07 14:17:35 +00:00
|
|
|
successReturnToOrRedirect: config.serverURL + '/',
|
|
|
|
failureRedirect: config.serverURL + '/'
|
2017-04-11 21:41:14 +00:00
|
|
|
})
|
|
|
|
)
|