2020-04-13 07:18:31 -04:00
|
|
|
import { NextFunction, Request, Response, Router } from 'express'
|
2020-04-13 06:55:08 -04:00
|
|
|
import passport from 'passport'
|
|
|
|
import * as DropboxStrategy from 'passport-dropbox-oauth2'
|
2020-04-13 07:18:31 -04:00
|
|
|
import { config } from '../../../config'
|
2020-04-13 07:09:49 -04:00
|
|
|
import { AuthMiddleware } from '../interface'
|
2020-04-13 07:18:31 -04:00
|
|
|
import { passportGeneralCallback } from '../utils'
|
2017-04-11 17:41:14 -04:00
|
|
|
|
2020-04-13 06:55:08 -04:00
|
|
|
export const dropboxAuth = Router()
|
2017-04-11 17:41:14 -04:00
|
|
|
|
2020-04-13 07:18:31 -04:00
|
|
|
export const DropboxMiddleware: AuthMiddleware = {
|
2020-04-13 07:09:49 -04:00
|
|
|
getMiddleware (): Router {
|
|
|
|
passport.use(new DropboxStrategy({
|
|
|
|
apiVersion: '2',
|
|
|
|
clientID: config.dropbox.clientID,
|
|
|
|
clientSecret: config.dropbox.clientSecret,
|
|
|
|
callbackURL: config.serverURL + '/auth/dropbox/callback'
|
|
|
|
}, passportGeneralCallback))
|
2017-04-11 17:41:14 -04:00
|
|
|
|
2020-04-13 07:09:49 -04:00
|
|
|
dropboxAuth.get('/auth/dropbox', function (req: Request, res: Response, next: NextFunction) {
|
|
|
|
passport.authenticate('dropbox-oauth2')(req, res, next)
|
|
|
|
})
|
|
|
|
dropboxAuth.get('/auth/dropbox/callback',
|
|
|
|
passport.authenticate('dropbox-oauth2', {
|
|
|
|
successReturnToOrRedirect: config.serverURL + '/',
|
|
|
|
failureRedirect: config.serverURL + '/'
|
|
|
|
})
|
|
|
|
)
|
|
|
|
return dropboxAuth
|
|
|
|
}
|
|
|
|
}
|