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:
David Mehren 2020-05-16 15:52:11 +02:00
parent 9c720183aa
commit 08655f06f9
No known key found for this signature in database
GPG key ID: 6017AF117F9756CB
2 changed files with 14 additions and 3 deletions

View file

@ -36,7 +36,7 @@ export type Profile = {
id: string;
username: string;
displayName: string;
emails: any[];
emails: string[];
avatarUrl: string;
profileUrl: string;
provider: ProviderEnum;
@ -125,7 +125,7 @@ export class User extends Model<User> {
}
break
case ProviderEnum.dropbox:
photo = generateAvatarURL('', profile.emails[0].value, bigger)
photo = generateAvatarURL('', profile.emails[0], bigger)
break
case ProviderEnum.google:
photo = profile.photos[0].value

View file

@ -2,6 +2,7 @@ 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'
@ -14,7 +15,17 @@ export const DropboxMiddleware: AuthMiddleware = {
clientID: config.dropbox.clientID,
clientSecret: config.dropbox.clientSecret,
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) {
passport.authenticate('dropbox-oauth2')(req, res, next)