mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04: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 { InternalOAuthError, Strategy as OAuth2Strategy } from 'passport-oauth2'
|
||||||
import { config } from '../../../config'
|
import { config } from '../../../config'
|
||||||
import { PassportProfile, ProviderEnum } from '../utils'
|
import { PassportProfile, ProviderEnum } from '../utils'
|
||||||
|
import { logger } from '../../../logger'
|
||||||
|
|
||||||
function extractProfileAttribute (data, path: string): string {
|
function extractProfileAttribute (data, path: string): string {
|
||||||
// can handle stuff like `attrs[0].name`
|
// can handle stuff like `attrs[0].name`
|
||||||
|
@ -15,14 +16,33 @@ function extractProfileAttribute (data, path: string): string {
|
||||||
|
|
||||||
function parseProfile (data): Partial<PassportProfile> {
|
function parseProfile (data): Partial<PassportProfile> {
|
||||||
const username = extractProfileAttribute(data, config.oauth2.userProfileUsernameAttr)
|
const username = extractProfileAttribute(data, config.oauth2.userProfileUsernameAttr)
|
||||||
const displayName = extractProfileAttribute(data, config.oauth2.userProfileDisplayNameAttr)
|
let displayName: string | undefined
|
||||||
const email = extractProfileAttribute(data, config.oauth2.userProfileEmailAttr)
|
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 {
|
return {
|
||||||
id: username,
|
id: username,
|
||||||
username: username,
|
username: username,
|
||||||
displayName: displayName,
|
displayName: displayName,
|
||||||
emails: [email]
|
emails: emails
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue