2021-06-12 07:38:44 +08:00
|
|
|
import {Router} from "express";
|
|
|
|
import passport from "passport";
|
|
|
|
import {Strategy as TwitterStrategy} from "passport-twitter";
|
2017-04-12 05:41:14 +08:00
|
|
|
|
2021-06-12 07:38:44 +08:00
|
|
|
import * as config from "../../config";
|
|
|
|
import {passportGeneralCallback, setReturnToFromReferer} from "../utils";
|
2017-04-12 05:41:14 +08:00
|
|
|
|
2021-06-12 07:38:44 +08:00
|
|
|
const twitterAuth = Router()
|
|
|
|
export = module.exports
|
2017-04-12 05:41:14 +08:00
|
|
|
|
|
|
|
passport.use(new TwitterStrategy({
|
|
|
|
consumerKey: config.twitter.consumerKey,
|
|
|
|
consumerSecret: config.twitter.consumerSecret,
|
2018-03-07 15:17:35 +01:00
|
|
|
callbackURL: config.serverURL + '/auth/twitter/callback'
|
2017-04-12 05:41:14 +08:00
|
|
|
}, passportGeneralCallback))
|
|
|
|
|
|
|
|
twitterAuth.get('/auth/twitter', function (req, res, next) {
|
|
|
|
setReturnToFromReferer(req)
|
|
|
|
passport.authenticate('twitter')(req, res, next)
|
|
|
|
})
|
|
|
|
|
|
|
|
// twitter auth callback
|
|
|
|
twitterAuth.get('/auth/twitter/callback',
|
|
|
|
passport.authenticate('twitter', {
|
2018-03-07 15:17:35 +01:00
|
|
|
successReturnToOrRedirect: config.serverURL + '/',
|
|
|
|
failureRedirect: config.serverURL + '/'
|
2017-04-12 05:41:14 +08:00
|
|
|
})
|
|
|
|
)
|