2017-04-11 21:41:14 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const Router = require('express').Router
|
|
|
|
const passport = require('passport')
|
|
|
|
const DropboxStrategy = require('passport-dropbox-oauth2').Strategy
|
|
|
|
const config = require('../../../config')
|
2019-05-30 22:27:56 +00:00
|
|
|
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
|
2017-04-11 21:41:14 +00:00
|
|
|
|
|
|
|
let dropboxAuth = module.exports = Router()
|
|
|
|
|
|
|
|
passport.use(new DropboxStrategy({
|
|
|
|
apiVersion: '2',
|
|
|
|
clientID: config.dropbox.clientID,
|
|
|
|
clientSecret: config.dropbox.clientSecret,
|
2018-03-07 14:17:35 +00:00
|
|
|
callbackURL: config.serverURL + '/auth/dropbox/callback'
|
2017-04-11 21:41:14 +00:00
|
|
|
}, passportGeneralCallback))
|
|
|
|
|
|
|
|
dropboxAuth.get('/auth/dropbox', function (req, res, next) {
|
|
|
|
setReturnToFromReferer(req)
|
|
|
|
passport.authenticate('dropbox-oauth2')(req, res, next)
|
|
|
|
})
|
|
|
|
|
|
|
|
// dropbox auth callback
|
|
|
|
dropboxAuth.get('/auth/dropbox/callback',
|
|
|
|
passport.authenticate('dropbox-oauth2', {
|
2018-03-07 14:17:35 +00:00
|
|
|
successReturnToOrRedirect: config.serverURL + '/',
|
|
|
|
failureRedirect: config.serverURL + '/'
|
2017-04-11 21:41:14 +00:00
|
|
|
})
|
|
|
|
)
|