mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-17 06:27:24 +00:00
auth/facebook: Migrate to AuthMiddleware
Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
620468e843
commit
dd55c947cc
3 changed files with 33 additions and 30 deletions
|
@ -1,28 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const Router = require('express').Router
|
||||
const passport = require('passport')
|
||||
const FacebookStrategy = require('passport-facebook').Strategy
|
||||
|
||||
const config = require('../../../config')
|
||||
const { passportGeneralCallback } = require('../utils')
|
||||
|
||||
let facebookAuth = module.exports = Router()
|
||||
|
||||
passport.use(new FacebookStrategy({
|
||||
clientID: config.facebook.clientID,
|
||||
clientSecret: config.facebook.clientSecret,
|
||||
callbackURL: config.serverURL + '/auth/facebook/callback'
|
||||
}, passportGeneralCallback))
|
||||
|
||||
facebookAuth.get('/auth/facebook', function (req, res, next) {
|
||||
passport.authenticate('facebook')(req, res, next)
|
||||
})
|
||||
|
||||
// facebook auth callback
|
||||
facebookAuth.get('/auth/facebook/callback',
|
||||
passport.authenticate('facebook', {
|
||||
successReturnToOrRedirect: config.serverURL + '/',
|
||||
failureRedirect: config.serverURL + '/'
|
||||
})
|
||||
)
|
31
lib/web/auth/facebook/index.ts
Normal file
31
lib/web/auth/facebook/index.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import passport from 'passport'
|
||||
import { config } from '../../../config'
|
||||
import { AuthMiddleware } from '../interface'
|
||||
import { Router } from 'express'
|
||||
import { passportGeneralCallback } from '../utils'
|
||||
import { Strategy as FacebookStrategy } from 'passport-facebook'
|
||||
|
||||
export const FacebookMiddleware: AuthMiddleware = {
|
||||
getMiddleware (): Router {
|
||||
const facebookAuth = Router()
|
||||
passport.use(new FacebookStrategy({
|
||||
clientID: config.facebook.clientID,
|
||||
clientSecret: config.facebook.clientSecret,
|
||||
callbackURL: config.serverURL + '/auth/facebook/callback'
|
||||
}, passportGeneralCallback
|
||||
))
|
||||
|
||||
facebookAuth.get('/auth/facebook', function (req, res, next) {
|
||||
passport.authenticate('facebook')(req, res, next)
|
||||
})
|
||||
|
||||
// facebook auth callback
|
||||
facebookAuth.get('/auth/facebook/callback',
|
||||
passport.authenticate('facebook', {
|
||||
successReturnToOrRedirect: config.serverURL + '/',
|
||||
failureRedirect: config.serverURL + '/'
|
||||
})
|
||||
)
|
||||
return facebookAuth
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ import passport from 'passport'
|
|||
import { config } from '../../config'
|
||||
import { logger } from '../../logger'
|
||||
import { User } from '../../models'
|
||||
import facebook from './facebook'
|
||||
import { FacebookMiddleware } from './facebook'
|
||||
import { TwitterMiddleware } from './twitter'
|
||||
import github from './github'
|
||||
import gitlab from './gitlab'
|
||||
|
@ -43,7 +43,7 @@ passport.deserializeUser(function (id: string, done) {
|
|||
})
|
||||
})
|
||||
|
||||
if (config.isFacebookEnable) AuthRouter.use(facebook)
|
||||
if (config.isFacebookEnable) AuthRouter.use(FacebookMiddleware.getMiddleware())
|
||||
if (config.isTwitterEnable) AuthRouter.use(TwitterMiddleware.getMiddleware())
|
||||
if (config.isGitHubEnable) AuthRouter.use(github)
|
||||
if (config.isGitLabEnable) AuthRouter.use(gitlab)
|
||||
|
|
Loading…
Add table
Reference in a new issue