Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Cannot add a samaccountname claim to a Microsoft Entra ID token

ErrorThe samaccountname claim is not in the token

Short answer

Entra ID has no optional claim for a user's sAMAccountName; the sam_account_name option exists only for the groups claim. Add the claim under Attributes & Claims with the source attribute onpremisessamaccountname, make sure the user is synced from on-premises, and allow mapped claims on the app, or the token request fails.

  • Applies to Microsoft Entra ID, Microsoft Entra Connect Sync, OpenID Connect v2.0
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Decode a real token for your app and list its claims. Paste the token into the Microsoft debugging site and look for the claim by name. Use it for debugging only.

    # open https://jwt.ms and paste the id_token or access_token for your own app
  2. 2Match what you see, then jump to its fix

    1. 1The optional claims list in Token configuration has no sAMAccountName entry for usersThe claim was requested as an optional claim, where it does not existFix
    2. 2The claim appears for some users and is empty or absent for othersThe user is cloud-only, so there is no on-premises value to emitFix
    3. 3AADSTS50146 when signing in after adding the custom claimClaims customization needs a custom signing key or acceptMappedClaimsFix
    4. 4The claim is in the ID token but not in the access token, or the reverseYou are reading the wrong tokenFix

What does the error look like?

  • The samaccountname claim is not in the token
  • AADSTS50146
  • AADSTS501461: _AcceptMappedClaims is only supported for a token audience matching the application GUID or an audience within the tenant's verified domains

Cause 1 of 4

The claim was requested as an optional claim, where it does not exist

1Check

The optional claims reference lists claims such as upn, email, ipaddr and onprem_sid. The sam_account_name value is an additionalProperty of the groups claim only.

# Entra admin center > App registrations > your app > Token configuration

2Fix

Use claims customization instead: in Enterprise apps, open the app, choose Single sign-on, and under Attributes & Claims add a claim whose source attribute is onpremisessamaccountname. The documentation describes that attribute as the SAM account name synced from on-premises.

# Enterprise apps > your app > Single sign-on > Attributes & Claims
# Add new claim
#   Name:             samaccountname
#   Source attribute: user.onpremisessamaccountname

3Verify

Sign in again and decode the new token.

# jwt.ms: the samaccountname claim shows the value

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 4

The user is cloud-only, so there is no on-premises value to emit

1Check

The attribute holds the SAM account name synced from on-premises. A user created only in the cloud has none. Compare a synced user with a cloud-only user.

# jwt.ms: decode a token for each of the two users and compare

2Fix

Sync the account from on-premises with Microsoft Entra Connect Sync, or choose a different source attribute (for example an extension attribute) for cloud-only users, using a claim condition by user type.

# Manage claim > Claim conditions
#   User type: Members
#   Source:    user.onpremisessamaccountname

3Verify

Decode a token for a cloud-only user and confirm the fallback value.

# jwt.ms

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 4

Claims customization needs a custom signing key or acceptMappedClaims

1Check

Customizing claims changes the token content. Entra ID then requires either a custom signing key or acceptMappedClaims set in the app manifest, and returns AADSTS50146 without one.

# Entra admin center > App registrations > your app > Manifest > search acceptMappedClaims

2Fix

For a single-tenant app, set acceptMappedClaims to true in the manifest. Never do this for a multitenant app; use a custom signing key there. The token audience must also be your app GUID or an identifier URI on a verified domain, or AADSTS501461 is returned.

"acceptMappedClaims": true

3Verify

Sign in again; the error code no longer appears.

# jwt.ms: decode the token

Confirmed by learn.microsoft.com

Did this fix it?

Cause 4 of 4

You are reading the wrong token

1Check

An access token is built from the manifest of the resource it is for, not from the client's. A token requested for Microsoft Graph never shows claims you set on your own app.

# jwt.ms: check the aud claim of the token you decoded

2Fix

Request a token for your own API (its scope), and set the claim on that API's app registration. Read the ID token if the claim is for the signed-in user in your web app.

# scope: api://<your-api-client-id>/access_as_user

3Verify

Decode the token whose aud is your API.

# jwt.ms

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Decide early which token (ID or access) carries the claim, and test with a token for your own app.
  • Keep a claim condition for cloud-only users so the claim is never empty.
  • Do not use mutable claims such as upn or email for authorization; use the object ID.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.