# Best way for users to link their Azure AD account

**URL:** <https://community.auth0.com/t/best-way-for-users-to-link-their-azure-ad-account/196762>\
**Category:** Get Help\
**Tags:** azure-ad-enterprise-connection, connections\
**Created:** [January 30, 2026, 5:08pm UTC](https://community.auth0.com/t/best-way-for-users-to-link-their-azure-ad-account/196762 "2026-01-30T17:08:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry5](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/harry5/32/60088_2.png) [@harry5](https://community.auth0.com/u/harry5)\
**Post date:** [January 30, 2026, 5:08pm UTC](https://community.auth0.com/t/best-way-for-users-to-link-their-azure-ad-account/196762/1 "2026-01-30T17:08:59Z")

</div>

Details:

- Platform is invite only
- All users will have Username-Password-Authentication primary accounts
- Some users may want to link their accounts to their Azure AD/Entra ID company accounts
- They can then use a SSO Entra button to login to their account
- This is setup via the common Microsoft endpoint so any user can do it.

My problem is:

Using the azure ad connection creates a empty account, I do not want any person to be able to do this. It seems the solution is an action to block these and delete the created account.

However, the flow in the front end seems to be:

- User logins in via Username-Password-Authentication account
- They click a button which prompts azure ad sign in
- This account is then linked to the primary account

How would you distinguish between a user wanting to link their entra account and any person using the SSO button.

Any suggestions on the best and easiest way to implement this.

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [January 30, 2026, 7:27pm UTC](https://community.auth0.com/t/best-way-for-users-to-link-their-azure-ad-account/196762/3 "2026-01-30T19:27:21Z")

</div>

Hi @harry5,

Welcome to the Auth0 Community!

To prevent unwanted access, as you have mentioned as well you must implement a **Post-Login Action** that acts as a bouncer by evaluating the user’s identity structure before they are fully authorized. This Action is essential because it detects the “ghost” account at the moment of creation, blocks the login session, and uses the **Auth0 Management API** to immediately delete the unauthorized record from your database.

The distinction between a **Ghost Account** and a **Legitimate User** is found in the `event.user.identities` array. A ghost account appears as a standalone Entra ID profile with a single identity entry, which signals to your Action that this user has no pre-existing “Primary” account and should be deleted. For example, if `identities.length === 1` and the provider is `waad`, the Action executes `management.users.delete()` to wipe the record instantly.

In order to tackle another possible distinction, once the accounts are linked, the Auth0 Action will always recognize that the user profile was originally anchored to the **Username-Password-Authentication** identity. Even when the user clicks the “Login with AD” button, Auth0 identifies the incoming Entra ID credentials as a “secondary” identity that belongs to the primary database account.

I hope this helps answer your inquiry and if you have further questions please let me know below!  
Best regards,  
Remus

---

<div class="post-metadata">

**Author:** ![harry5](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/harry5/32/60088_2.png) [@harry5](https://community.auth0.com/u/harry5)\
**Post date:** [January 30, 2026, 7:57pm UTC](https://community.auth0.com/t/best-way-for-users-to-link-their-azure-ad-account/196762/5 "2026-01-30T19:57:20Z")

</div>

Hi

The issue I have, is before the link happens.

The entra id account has to exist before linking. There does not seem to be any mechanism to add an account to your main account otherwise.

So how would you tell the difference between a legit entra id account that is about to be linked and ghost account inside your action to deny entra accounts.

Thanks

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [February 4, 2026, 7:40pm UTC](https://community.auth0.com/t/best-way-for-users-to-link-their-azure-ad-account/196762/6 "2026-02-04T19:40:29Z")

</div>

Hi @harry5,

You are asking how an Auth0 Post-Login Action can tell a user who wants to link their Microsoft Entra ID account apart from someone who clicks the Entra SSO button on the login page and creates an empty account, when the Microsoft common endpoint allows any Microsoft user to sign in.

**Solution:** Move account linking out of the login page and into your signed-in application. Only a user who is already authenticated with a Username-Password-Authentication account can start a link to an Entra ID identity. The login page SSO button then only signs in users who have an existing linked identity, and the Action blocks any Entra login that does not match a linked account.

1. **Add** a "Link Company account" button to the authenticated area of your application. Show this button only to users who have a valid session with their primary account.
2. **Start** the link from your backend. Your backend starts the Entra ID authentication for the secondary identity and receives the result. Do not rely on a query parameter from the browser to mark the request as a link.
3. **Link** the Entra ID identity to the primary user by calling the Management API from your backend, or by using the account-linking flow that requires the primary user's access token. The primary user's session proves which account the link belongs to.
4. **Block** unlinked Entra logins in a Post-Login Action. Check whether the authenticating user has a linked secondary identity with the `waad` connection. If the user has no existing link, deny the login with an access denial in the Action, rather than creating or deleting accounts inside the Action.
5. **Clean up** any empty Entra accounts created before the change with a separate scheduled script. The script uses the Management API to list users created in the Entra connection with no linked primary account, then reviews and deletes them in batches.

Additionally, you can review our documentation on **[User-Initiated Account Linking: Client-Side Implementation](https://auth0.com/docs/manage-users/user-accounts/user-account-linking/user-initiated-account-linking-client-side-implementation?_gl=1*bzl4vs*_gcl_au*MTg5MDY3OTU5Mi4xNzkyNDE5Njkw*_ga*MTcyMTA4NDI5Ni4xNzY4OTMxMjA1*_ga_QKMSDV5369*czE3OTI0NDkxMzckbzgwJGcxJHQxNzkyNDUyMjA4JGozOSRsMCRoMA)** or **[User Account Linking: Server-Side Implementation](https://auth0.com/docs/manage-users/user-accounts/user-account-linking/suggested-account-linking-server-side-implementation?_gl=1*t1025b*_gcl_au*MTg5MDY3OTU5Mi4xNzkyNDE5Njkw*_ga*MTcyMTA4NDI5Ni4xNzY4OTMxMjA1*_ga_QKMSDV5369*czE3OTI0NDkxMzckbzgwJGcxJHQxNzkyNDUyMjYwJGo2MCRsMCRoMA)** as it addressed the issue directly.

Please follow up if you need further assistance designing the linking flow or the Post-Login Action.

I hope this helps.  
Best regards,  
Remus

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 23, 2026, 10:29pm UTC](https://community.auth0.com/t/best-way-for-users-to-link-their-azure-ad-account/196762/7 "2026-02-23T22:29:34Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
