mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 18:25:21 -04:00
Profile.emails is now a string array 🏷️
Dropbox wrapped their email attribute in another object. We now unwrap this object in the DropboxMiddleware and don't need to special-case the email attribute in User.parsePhotoByProfile and the Profile type anymore. Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
9c720183aa
commit
08655f06f9
2 changed files with 14 additions and 3 deletions
|
@ -36,7 +36,7 @@ export type Profile = {
|
||||||
id: string;
|
id: string;
|
||||||
username: string;
|
username: string;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
emails: any[];
|
emails: string[];
|
||||||
avatarUrl: string;
|
avatarUrl: string;
|
||||||
profileUrl: string;
|
profileUrl: string;
|
||||||
provider: ProviderEnum;
|
provider: ProviderEnum;
|
||||||
|
@ -125,7 +125,7 @@ export class User extends Model<User> {
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case ProviderEnum.dropbox:
|
case ProviderEnum.dropbox:
|
||||||
photo = generateAvatarURL('', profile.emails[0].value, bigger)
|
photo = generateAvatarURL('', profile.emails[0], bigger)
|
||||||
break
|
break
|
||||||
case ProviderEnum.google:
|
case ProviderEnum.google:
|
||||||
photo = profile.photos[0].value
|
photo = profile.photos[0].value
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { NextFunction, Request, Response, Router } from 'express'
|
||||||
import passport from 'passport'
|
import passport from 'passport'
|
||||||
import { Strategy as DropboxStrategy } from 'passport-dropbox-oauth2'
|
import { Strategy as DropboxStrategy } from 'passport-dropbox-oauth2'
|
||||||
import { config } from '../../../config'
|
import { config } from '../../../config'
|
||||||
|
import { User } from '../../../models'
|
||||||
import { AuthMiddleware } from '../interface'
|
import { AuthMiddleware } from '../interface'
|
||||||
import { passportGeneralCallback } from '../utils'
|
import { passportGeneralCallback } from '../utils'
|
||||||
|
|
||||||
|
@ -14,7 +15,17 @@ export const DropboxMiddleware: AuthMiddleware = {
|
||||||
clientID: config.dropbox.clientID,
|
clientID: config.dropbox.clientID,
|
||||||
clientSecret: config.dropbox.clientSecret,
|
clientSecret: config.dropbox.clientSecret,
|
||||||
callbackURL: config.serverURL + '/auth/dropbox/callback'
|
callbackURL: config.serverURL + '/auth/dropbox/callback'
|
||||||
}, passportGeneralCallback))
|
}, (
|
||||||
|
accessToken: string,
|
||||||
|
refreshToken: string,
|
||||||
|
profile: any,
|
||||||
|
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) {
|
dropboxAuth.get('/auth/dropbox', function (req: Request, res: Response, next: NextFunction) {
|
||||||
passport.authenticate('dropbox-oauth2')(req, res, next)
|
passport.authenticate('dropbox-oauth2')(req, res, next)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue