Skip to content

Microsoft (Azure Active Directory / Entra ID) provider, creates users with wrong emails. #9229

@mbuptivo

Description

@mbuptivo

Operating System

Windows >=10

Environment (if applicable)

Chrome 139

Firebase SDK Version

^12.1.0

Firebase SDK Product(s)

Auth

Project Tooling

  • Firebase 12.1.0
  • Firebase UI 6.1.0
  • JavaSscript

Detailed Problem Description

I’m trying to integrate login with Firebase Auth and Azure Active Directory / Entra ID as a provider.
The flow works, the user is created or logs in correctly, but the email associated with the user is wrong if the user is an “external user” in AD.

NOTE: External AD users are invited through an email, for example "[email protected]". The user created in AD has a "User principal name" built like this: "myemail_ gmail.com#EXT#@myaddomain.onmicrosoft.com".
However, these users do have a correct email assigned in their profile, in this case "[email protected]".

I checked that after signIn, the user looks like this:

{
  "uid": "yOMsXXXXXXXXXXXXXpPM72",
  "email": "myemail_ gmail.com#EXT#@myaddomain.onmicrosoft.com",
  "emailVerified": false,
  ...
  "providerData": [
    {
      "uid": "304XXXXXXXXXXXXX5e6",
      "displayName": "XXXXXXXXXXX",
      "email": "myemail_ gmail.com#EXT#@myaddomain.onmicrosoft.com",
      "providerId": "microsoft.com"
    }
  ],
  "tokensValidAfterTime": null,
  "multiFactor": null
}

But the content of the additional user info is (notice the correct "mail" value):

"additionalUserInfo": {
  "providerId": "microsoft.com",
  "profile": {
    "businessPhones": [],
    "preferredLanguage": null,
    "mail": "[email protected]",
    "mobilePhone": null,
    "officeLocation": null,
    "displayName": "XXXXXXXXXX",
    "surname": null,
    "givenName": null,
    "jobTitle": null,
...
    "userPrincipalName": "myemail_ gmail.com#EXT#@myaddomain.onmicrosoft.com"
  },
  "isNewUser": true
}

I’m trying to figure out why the email chosen to create the user in Firebase Auth is the userPrincipalName instead of the user’s real email. What am I doing wrong?

Thanks.

Steps and code to reproduce issue

.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions