mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 17:25:16 -04:00
Move old backend code to old_src folder
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
c42d2223e8
commit
7b9f9a487b
97 changed files with 7 additions and 7 deletions
41
old_src/lib/web/auth/dropbox/index.ts
Normal file
41
old_src/lib/web/auth/dropbox/index.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { NextFunction, Request, Response, Router } from 'express'
|
||||
import passport from 'passport'
|
||||
import { Strategy as DropboxStrategy } from 'passport-dropbox-oauth2'
|
||||
import { config } from '../../../config'
|
||||
import { User } from '../../../models'
|
||||
import { AuthMiddleware } from '../interface'
|
||||
import { passportGeneralCallback } from '../utils'
|
||||
|
||||
export const dropboxAuth = Router()
|
||||
|
||||
export const DropboxMiddleware: AuthMiddleware = {
|
||||
getMiddleware (): Router {
|
||||
passport.use(new DropboxStrategy({
|
||||
apiVersion: '2',
|
||||
clientID: config.dropbox.clientID,
|
||||
clientSecret: config.dropbox.clientSecret,
|
||||
callbackURL: config.serverURL + '/auth/dropbox/callback'
|
||||
}, (
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
profile,
|
||||
done: (err?: Error | null, user?: User) => void
|
||||
): void => {
|
||||
// the Dropbox plugin wraps the email addresses in an object
|
||||
// see https://github.com/florianheinemann/passport-dropbox-oauth2/blob/master/lib/passport-dropbox-oauth2/strategy.js#L146
|
||||
profile.emails = profile.emails.map(element => element.value)
|
||||
passportGeneralCallback(accessToken, refreshToken, profile, done)
|
||||
}))
|
||||
|
||||
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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue