mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-03-15 04:11:58 +00:00
Merge pull request #411 from dalcde/oauth3
Allow for undefined email and displayName
This commit is contained in:
commit
04a652c3a6
1 changed files with 23 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
import { InternalOAuthError, Strategy as OAuth2Strategy } from 'passport-oauth2'
|
||||
import { config } from '../../../config'
|
||||
import { PassportProfile, ProviderEnum } from '../utils'
|
||||
import { logger } from '../../../logger'
|
||||
|
||||
function extractProfileAttribute (data, path: string): string {
|
||||
// can handle stuff like `attrs[0].name`
|
||||
|
@ -15,14 +16,33 @@ function extractProfileAttribute (data, path: string): string {
|
|||
|
||||
function parseProfile (data): Partial<PassportProfile> {
|
||||
const username = extractProfileAttribute(data, config.oauth2.userProfileUsernameAttr)
|
||||
const displayName = extractProfileAttribute(data, config.oauth2.userProfileDisplayNameAttr)
|
||||
const email = extractProfileAttribute(data, config.oauth2.userProfileEmailAttr)
|
||||
let displayName: string | undefined
|
||||
try {
|
||||
// This may fail if the config.oauth2.userProfileDisplayNameAttr is undefined,
|
||||
// or it is foo.bar and data["foo"] is undefined.
|
||||
displayName = extractProfileAttribute(data, config.oauth2.userProfileDisplayNameAttr)
|
||||
} catch (e) {
|
||||
displayName = undefined
|
||||
logger.debug('\'id_token[%s]\' is undefined. Setting \'displayName\' to \'undefined\'.\n%s', config.oauth2.userProfileDisplayNameAttr, e.message)
|
||||
}
|
||||
|
||||
const emails: string[] = []
|
||||
try {
|
||||
const email = extractProfileAttribute(data, config.oauth2.userProfileEmailAttr)
|
||||
if (email !== undefined) {
|
||||
emails.push(email)
|
||||
} else {
|
||||
logger.debug('\'id_token[%s]\' is undefined. Setting \'emails\' to [].', config.oauth2.userProfileEmailAttr)
|
||||
}
|
||||
} catch (e) {
|
||||
logger.debug('\'id_token[%s]\' is undefined. Setting \'emails\' to [].\n%s', config.oauth2.userProfileEmailAttr, e.message)
|
||||
}
|
||||
|
||||
return {
|
||||
id: username,
|
||||
username: username,
|
||||
displayName: displayName,
|
||||
emails: [email]
|
||||
emails: emails
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue