mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 10:16:32 -05:00
added auth/twitter.ts
Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
e5961336b7
commit
c075eb769f
3 changed files with 35 additions and 30 deletions
|
@ -4,7 +4,7 @@ import { config } from '../../config'
|
|||
import { logger } from '../../logger'
|
||||
import { User } from '../../models'
|
||||
import facebook from './facebook'
|
||||
import twitter from './twitter'
|
||||
import { TwitterMiddleware } from './twitter'
|
||||
import github from './github'
|
||||
import gitlab from './gitlab'
|
||||
import dropbox from './dropbox'
|
||||
|
@ -44,7 +44,7 @@ passport.deserializeUser(function (id: string, done) {
|
|||
})
|
||||
|
||||
if (config.isFacebookEnable) AuthRouter.use(facebook)
|
||||
if (config.isTwitterEnable) AuthRouter.use(twitter)
|
||||
if (config.isTwitterEnable) AuthRouter.use(TwitterMiddleware.getMiddleware())
|
||||
if (config.isGitHubEnable) AuthRouter.use(github)
|
||||
if (config.isGitLabEnable) AuthRouter.use(gitlab)
|
||||
if (config.isDropboxEnable) AuthRouter.use(dropbox)
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const Router = require('express').Router
|
||||
const passport = require('passport')
|
||||
const TwitterStrategy = require('passport-twitter').Strategy
|
||||
|
||||
const config = require('../../../config')
|
||||
const { passportGeneralCallback } = require('../utils')
|
||||
|
||||
let twitterAuth = module.exports = 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 + '/'
|
||||
})
|
||||
)
|
33
lib/web/auth/twitter/index.ts
Normal file
33
lib/web/auth/twitter/index.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue