hedgedoc/lib/web/auth/twitter/index.ts
Philip Molares c075eb769f
added auth/twitter.ts
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: David Mehren <dmehren1@gmail.com>
2020-04-25 16:04:14 +02:00

33 lines
1,014 B
TypeScript

import { Router } from 'express'
import passport from 'passport'
import { Strategy as TwitterStrategy } from 'passport-twitter'
import { config } from '../../../config'
import { passportGeneralCallback } from '../utils'
import { AuthMiddleware } from '../interface'
export const TwitterMiddleware: AuthMiddleware = {
getMiddleware (): Router {
const TwitterAuth = Router()
passport.use(new TwitterStrategy({
consumerKey: config.twitter.consumerKey,
consumerSecret: config.twitter.consumerSecret,
callbackURL: config.serverURL + '/auth/twitter/callback'
}, passportGeneralCallback))
TwitterAuth.get('/auth/twitter', function (req, res, next) {
passport.authenticate('twitter')(req, res, next)
})
// twitter auth callback
TwitterAuth.get('/auth/twitter/callback',
passport.authenticate('twitter', {
successReturnToOrRedirect: config.serverURL + '/',
failureRedirect: config.serverURL + '/'
})
)
return TwitterAuth
}
}