Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for azure ad b2c auth #7052

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lfernandes00
Copy link

I was having problems trying to implement azure ad b2c user flow in Azure AD auth strategy. I kept getting the error "Invalid email / username or password on sign in".

After running some tests I found out that the issue came from the JWT sent by AZURE AD B2C auth which do not contain email or preferred_username claims expected by Azure AD authentication. The JWT from b2c returns the user email on an array claim emails.

I fix this by changing the following lines in /server/modules/authentication/azure/authentication.js file.

I changed:

const usrEmail = _.get(profile, '_json.email', null) || _.get(profile, '_json.preferred_username')

To:

const emails = _.get(profile, '_json.emails', null)
const usrEmail = _.get(profile, '_json.email', null) || _.get(profile, '_json.preferred_username') || emails[0]

Also, the JWT from B2C doesn't contain the oid claim. So I also change this lines to fix it:

From:

profile: {
              id: profile.oid,
              displayName: profile.displayName,
              email: usrEmail,
              picture: ''
            }

To:

const id = _.get(profile, '_json.sub', null)
profile: {
              id: profile.oid || id,
              displayName: profile.displayName,
              email: usrEmail,
              picture: ''
            }

I tested everything and it worked as expected.

@NGPixel I'd like to get your feedback as soon as possible. Thank you!

@auto-assign auto-assign bot requested a review from NGPixel March 7, 2024 11:54
@lfernandes00 lfernandes00 requested a review from NGPixel May 2, 2024 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants