Search code examples
c#azure-active-directoryazure-ad-b2c

When creating a new user, why is UPN set as login, and not Email?


I have a C# script, that creates a user with the following parameters: AccountEnabled, DisplayName, MailNickname, Mail, UserPrincipalName, and PasswordProfile.

When I create a new user, instead of logging in with the mail, the one that works is the UPN. My flow is set to require email for the login, as per the screenshot below. An image of an Azure B2C flow

The user is created, but logging in with the email and password doesn't work, instead it is UPN and password that works. Why is that?


Solution

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

    I created an Azure AD B2C user via Microsoft Graph API by using below query:

    POST https://graph.microsoft.com/v1.0/users
    
    {
    "displayName": "testb2c",
    "identities": [
    {
    "signInType": "emailAddress",
    "issuer": "tenantb2c.onmicrosoft.com",
    "issuerAssignedId": "[email protected]"
    }
    ],
    "passwordProfile": {
    "password": "****",
    "forceChangePasswordNextSignIn": false
    },
    "passwordPolicies": "DisablePasswordExpiration"
    }
    

    enter image description here

    Now, I created an Azure AD B2C sign-in user flow like below:

    enter image description here

    When I executed the user flow, I used email address to sign-in like below:

    enter image description here

    The user got successfully signed-in with email address:

    enter image description here

    To resolve the issue, make sure to create the user by adding the email to the identities collection. By doing this the user will be able to sign-in with the email address.

    Reference:

    Create User - Microsoft Graph v1.0 | Microsoft Learn