Search code examples
azureazure-ad-b2cmsal-react

Azure AD B2C claim for username sign up


I have created a Azure AD B2C directory/tenant and created a new sign up/sign in user flow as per below: enter image description here

Notice that the Identity Provider is set to user id signup (i.e. usernames).

I've created a user with the username hughbe.

Registered users

When I get a JWT access token using the following code:

const { instance, accounts } = useMsal();
const token = await instance.acquireTokenSilent({account: accounts[0], scopes: ...});

I only get the following idTokenClaims enter image description here

Is it possible to configure Azure AD B2C to include a user's username field in the list of Application Claims? It doesn't appear in the list:

enter image description here


Solution

  • I tried to reproduce the same in my environment and got the below results:

    In my B2C tenant, I created one Sign up and sign in user flow with same properties as you like below:

    enter image description here

    Now, I created one Azure AD B2C user with username as sri like below:

    enter image description here

    When I ran the user flow, it displayed sign in screen with username as below:

    enter image description here

    If the user signs in successfully, they got code in their address bar along with redirect Uri like this:

    enter image description here

    I used the above code to generate token via Postman like below:

    enter image description here

    When I decoded this token, I got the same claims as you like below:

    enter image description here

    Please note that, it's not possible to include user's username field in the list of Application Claims.

    While running user flows, username won't be returned as token claim. Alternatively, you can make use of custom policies by adding signinname as output claim in the policy like below:

    <OutputClaim  ClaimTypeReferenceId="signinname" />
    

    References:

    SignUpOrSignin with_Username policy - GitHub by Sipower

    Send the user principal name via claims - Stack Overflow by Jas Suri-MSFT