2017-04-11 21:41:14 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const Router = require('express').Router
|
|
|
|
const passport = require('passport')
|
|
|
|
const GithubStrategy = require('passport-github').Strategy
|
|
|
|
const config = require('../../../config')
|
2017-05-16 18:42:44 +00:00
|
|
|
const response = require('../../../response')
|
2017-04-11 21:41:14 +00:00
|
|
|
const {setReturnToFromReferer, passportGeneralCallback} = require('../utils')
|
|
|
|
|
|
|
|
let githubAuth = module.exports = Router()
|
|
|
|
|
|
|
|
passport.use(new GithubStrategy({
|
|
|
|
clientID: config.github.clientID,
|
|
|
|
clientSecret: config.github.clientSecret,
|
|
|
|
callbackURL: config.serverurl + '/auth/github/callback'
|
|
|
|
}, passportGeneralCallback))
|
|
|
|
|
|
|
|
githubAuth.get('/auth/github', function (req, res, next) {
|
|
|
|
setReturnToFromReferer(req)
|
|
|
|
passport.authenticate('github')(req, res, next)
|
|
|
|
})
|
|
|
|
|
|
|
|
// github auth callback
|
|
|
|
githubAuth.get('/auth/github/callback',
|
|
|
|
passport.authenticate('github', {
|
|
|
|
successReturnToOrRedirect: config.serverurl + '/',
|
|
|
|
failureRedirect: config.serverurl + '/'
|
|
|
|
})
|
|
|
|
)
|
2017-05-16 18:42:44 +00:00
|
|
|
|
|
|
|
// github callback actions
|
|
|
|
githubAuth.get('/auth/github/callback/:noteId/:action', response.githubActions)
|