diff --git a/server/modules/authentication/oidc/authentication.js b/server/modules/authentication/oidc/authentication.js index d9fee5ad..c0e692ad 100644 --- a/server/modules/authentication/oidc/authentication.js +++ b/server/modules/authentication/oidc/authentication.js @@ -25,11 +25,26 @@ module.exports = { })() }, async (req, iss, sub, profile, cb) => { try { + // Extract email from multiple possible locations + const email = _.get(profile, '_json.' + conf.emailClaim) || + _.get(profile, '_json.email') || + _.get(profile, 'emails[0].value') || + _.get(profile, 'email') || + _.get(profile, conf.emailClaim) + + const displayName = _.get(profile, '_json.' + (conf.displayNameClaim || 'name')) || + _.get(profile, 'displayName') || + _.get(profile, '_json.name') || + _.get(profile, 'name.givenName', '') + ' ' + _.get(profile, 'name.familyName', '') + + WIKI.logger.info('OIDC profile: ' + JSON.stringify({ id: profile.id, email, displayName, keys: Object.keys(profile) })) + const user = await WIKI.db.users.processProfile({ providerKey: req.params.strategy, profile: { ...profile, - email: _.get(profile, '_json.' + conf.emailClaim) + email: email, + displayName: displayName.trim() } }) cb(null, user)