-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Core Library
MSAL.js (@azure/msal-browser)
Core Library Version
4.27.0
Wrapper Library
MSAL React (@azure/msal-react)
Wrapper Library Version
3.0.23
Public or Confidential Client?
Public
Description
The username property is no longer provided in AccountInfo for Azure B2C token.
I traced the problem to release 4.19.0. This was working in 4.18.0.
Here is the relevant react code:
const { instance } = useMsal();
const account = instance.getActiveAccount();
const username = account?.username; // This property is always empty starting in 4.19.0Here is a sample of the idToken from Azure B2C
{
"alg": "RS256",
"kid": "<redacted>",
"typ": "JWT"
}.{
"exp": 1765830198,
"nbf": 1765826598,
"ver": "1.0",
"iss": "https://<redacted>.b2clogin.com/<redacted>/v2.0/",
"sub": "9ea8c064-<redacted>",
"aud": "3740edc9-<redacted>",
"nonce": "019b2377-66b7-7953-b4aa-e8c748cdfa54",
"iat": 1765826598,
"auth_time": 1765826596,
"oid": "9ea8c064-<redacted>",
"emails": [
"[email protected]"
],
"tfp": "B2C_1_SignUpSignIn"
}.[Signature]I can workaround the problem by pulling the username from the emails claim.
const username = account?.idTokenClaims?.emails?.[0]Maybe the behavior in 4.18.0 where username is populated from this type of token was not supported? I'm confused because I didn't expect breaking changes in a minor release.
Error Message
No response
MSAL Logs
No response
Network Trace (Preferrably Fiddler)
- Sent
- Pending
MSAL Configuration
{
auth: {
clientId: import.meta.env.REACT_APP_AZURE_AD_CLIENT_ID ?? "",
authority: import.meta.env.REACT_APP_AZURE_AD_AUTHORITY,
knownAuthorities: [import.meta.env.REACT_APP_AZURE_AD_KNOWN_AUTHORITIES],
redirectUri: import.meta.env.REACT_APP_AZURE_AD_REDIRECT_URI,
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: false,
},
}Relevant Code Snippets
const { instance } = useMsal();
const account = instance.getActiveAccount();
const username = account?.username;Reproduction Steps
- Obtain an
idTokenfrom Azure B2C using a standard "sign-up-sign-in" flow - Use react hook
useMsal()to get an instance - Get the active account from the
IPublicClientApplicationinstance - Try to read the
usernameproperty on the returnedAccountInfo
Expected Behavior
Expected: username property populated withe the email address for the Azure B2C user. This is the observed behavior in 4.18.0
Identity Provider
Azure B2C Basic Policy
Browsers Affected (Select all that apply)
Firefox
Regression
@azure/msal-browser 4.18.0