mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 03:58:02 -05:00
auth/github: Migrate to AuthMiddleware
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
dd55c947cc
commit
e4b2acf53e
3 changed files with 38 additions and 33 deletions
|
@ -1,31 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const Router = require('express').Router
|
||||
const passport = require('passport')
|
||||
const GithubStrategy = require('passport-github').Strategy
|
||||
const config = require('../../../config')
|
||||
const response = require('../../../response')
|
||||
const { 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) {
|
||||
passport.authenticate('github')(req, res, next)
|
||||
})
|
||||
|
||||
// github auth callback
|
||||
githubAuth.get('/auth/github/callback',
|
||||
passport.authenticate('github', {
|
||||
successReturnToOrRedirect: config.serverURL + '/',
|
||||
failureRedirect: config.serverURL + '/'
|
||||
})
|
||||
)
|
||||
|
||||
// github callback actions
|
||||
githubAuth.get('/auth/github/callback/:noteId/:action', response.githubActions)
|
36
lib/web/auth/github/index.ts
Normal file
36
lib/web/auth/github/index.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { Router } from 'express'
|
||||
import passport from 'passport'
|
||||
import { Strategy as GithubStrategy } from 'passport-github'
|
||||
import { config } from '../../../config'
|
||||
import { response } from '../../../response'
|
||||
import { AuthMiddleware } from '../interface'
|
||||
import { passportGeneralCallback } from '../utils'
|
||||
|
||||
export const GithubMiddleware: AuthMiddleware = {
|
||||
getMiddleware (): Router {
|
||||
const githubAuth = 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) {
|
||||
passport.authenticate('github')(req, res, next)
|
||||
})
|
||||
|
||||
// github auth callback
|
||||
githubAuth.get('/auth/github/callback',
|
||||
passport.authenticate('github', {
|
||||
successReturnToOrRedirect: config.serverURL + '/',
|
||||
failureRedirect: config.serverURL + '/'
|
||||
})
|
||||
)
|
||||
|
||||
// github callback actions
|
||||
githubAuth.get('/auth/github/callback/:noteId/:action', response.githubActions)
|
||||
|
||||
return githubAuth
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ import { logger } from '../../logger'
|
|||
import { User } from '../../models'
|
||||
import { FacebookMiddleware } from './facebook'
|
||||
import { TwitterMiddleware } from './twitter'
|
||||
import github from './github'
|
||||
import { GithubMiddleware } from './github'
|
||||
import gitlab from './gitlab'
|
||||
import dropbox from './dropbox'
|
||||
import google from './google'
|
||||
|
@ -45,7 +45,7 @@ passport.deserializeUser(function (id: string, done) {
|
|||
|
||||
if (config.isFacebookEnable) AuthRouter.use(FacebookMiddleware.getMiddleware())
|
||||
if (config.isTwitterEnable) AuthRouter.use(TwitterMiddleware.getMiddleware())
|
||||
if (config.isGitHubEnable) AuthRouter.use(github)
|
||||
if (config.isGitHubEnable) AuthRouter.use(GithubMiddleware.getMiddleware())
|
||||
if (config.isGitLabEnable) AuthRouter.use(gitlab)
|
||||
if (config.isDropboxEnable) AuthRouter.use(dropbox)
|
||||
if (config.isGoogleEnable) AuthRouter.use(google)
|
||||
|
|
Loading…
Reference in a new issue