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
|
|
|
|
const config = require('../../../config')
|
|
|
|
const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
|
|
|
|
|
2017-09-04 08:04:20 +00:00
|
|
|
let googleAuth = module.exports = Router()
|
2017-04-11 21:41:14 +00:00
|
|
|
|
|
|
|
passport.use(new GoogleStrategy({
|
|
|
|
clientID: config.google.clientID,
|
|
|
|
clientSecret: config.google.clientSecret,
|
2018-03-07 14:17:35 +00:00
|
|
|
callbackURL: config.serverURL + '/auth/google/callback'
|
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)
|
|
|
|
})
|
|
|
|
// 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
|
|
|
})
|
|
|
|
)
|