2017-06-27 17:08:05 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const Router = require('express').Router
|
|
|
|
const passport = require('passport')
|
2020-02-27 15:49:05 +00:00
|
|
|
|
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')
|
2020-02-27 15:49:05 +00:00
|
|
|
const { OAuth2CustomStrategy } = require('./strategy')
|
2017-06-27 17:08:05 +00:00
|
|
|
|
2019-08-01 16:59:38 +00:00
|
|
|
const oauth2Auth = module.exports = Router()
|
2017-06-27 17:08:05 +00:00
|
|
|
|
|
|
|
passport.use(new OAuth2CustomStrategy({
|
|
|
|
authorizationURL: config.oauth2.authorizationURL,
|
|
|
|
tokenURL: config.oauth2.tokenURL,
|
|
|
|
clientID: config.oauth2.clientID,
|
|
|
|
clientSecret: config.oauth2.clientSecret,
|
|
|
|
callbackURL: config.serverURL + '/auth/oauth2/callback',
|
2020-02-27 18:13:58 +00:00
|
|
|
userProfileURL: config.oauth2.userProfileURL,
|
2020-05-11 13:57:58 +00:00
|
|
|
state: config.oauth2.state,
|
2020-02-27 18:13:58 +00:00
|
|
|
scope: config.oauth2.scope
|
2017-06-27 17:08:05 +00:00
|
|
|
}, passportGeneralCallback))
|
|
|
|
|
|
|
|
oauth2Auth.get('/auth/oauth2', function (req, res, next) {
|
|
|
|
setReturnToFromReferer(req)
|
|
|
|
passport.authenticate('oauth2')(req, res, next)
|
|
|
|
})
|
|
|
|
|
|
|
|
// github auth callback
|
|
|
|
oauth2Auth.get('/auth/oauth2/callback',
|
|
|
|
passport.authenticate('oauth2', {
|
2018-11-27 14:13:18 +00:00
|
|
|
successReturnToOrRedirect: config.serverURL + '/',
|
|
|
|
failureRedirect: config.serverURL + '/'
|
2017-06-27 17:08:05 +00:00
|
|
|
})
|
|
|
|
)
|