From f45d822b28e5a3b1913ab16b61f86de5fa0eecbe Mon Sep 17 00:00:00 2001 From: "l.fernandes" Date: Thu, 7 Mar 2024 11:16:48 +0000 Subject: [PATCH 1/2] Add support for azure ad b2c auth --- server/modules/authentication/azure/authentication.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/modules/authentication/azure/authentication.js b/server/modules/authentication/azure/authentication.js index a983d148..728d3cb9 100644 --- a/server/modules/authentication/azure/authentication.js +++ b/server/modules/authentication/azure/authentication.js @@ -37,12 +37,16 @@ module.exports = { useCookieInsteadOfSession: keyArray.length > 0, cookieEncryptionKeys: keyArray }, async (req, iss, sub, profile, cb) => { - const usrEmail = _.get(profile, '_json.email', null) || _.get(profile, '_json.preferred_username') + const emails = _.get(profile, '_json.emails', null); + const id = _.get(profile, '_json.sub', null); + + const usrEmail = _.get(profile, '_json.email', null) || _.get(profile, '_json.preferred_username') || emails[0] + try { const user = await WIKI.models.users.processProfile({ providerKey: req.params.strategy, profile: { - id: profile.oid, + id: profile.oid || id, displayName: profile.displayName, email: usrEmail, picture: '' From a8bc2035bae2d10624ffce3e87848be72566ef63 Mon Sep 17 00:00:00 2001 From: "l.fernandes" Date: Thu, 2 May 2024 09:48:19 +0100 Subject: [PATCH 2/2] Change default value to empty array --- server/modules/authentication/azure/authentication.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/modules/authentication/azure/authentication.js b/server/modules/authentication/azure/authentication.js index 728d3cb9..34282633 100644 --- a/server/modules/authentication/azure/authentication.js +++ b/server/modules/authentication/azure/authentication.js @@ -37,7 +37,7 @@ module.exports = { useCookieInsteadOfSession: keyArray.length > 0, cookieEncryptionKeys: keyArray }, async (req, iss, sub, profile, cb) => { - const emails = _.get(profile, '_json.emails', null); + const emails = _.get(profile, '_json.emails', []) const id = _.get(profile, '_json.sub', null); const usrEmail = _.get(profile, '_json.email', null) || _.get(profile, '_json.preferred_username') || emails[0]