Cannot add a samaccountname claim to a Microsoft Entra ID token
The samaccountname claim is not in the tokenShort 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.
Fix it fast
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 app2Match what you see, then jump to its fix
- 1
The 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
The 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
AADSTS50146 when signing in after adding the custom claimClaims customization needs a custom signing key or acceptMappedClaimsFix - 4
The claim is in the ID token but not in the access token, or the reverseYou are reading the wrong tokenFix
- 1
What does the error look like?
The samaccountname claim is not in the tokenAADSTS50146AADSTS501461: _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 configuration2Fix
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.onpremisessamaccountname3Verify
Sign in again and decode the new token.
# jwt.ms: the samaccountname claim shows the valueConfirmed by learn.microsoft.com
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 compare2Fix
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.onpremisessamaccountname3Verify
Decode a token for a cloud-only user and confirm the fallback value.
# jwt.msConfirmed by learn.microsoft.com
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 acceptMappedClaims2Fix
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": true3Verify
Sign in again; the error code no longer appears.
# jwt.ms: decode the tokenConfirmed by learn.microsoft.com
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 decoded2Fix
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_user3Verify
Decode the token whose aud is your API.
# jwt.msConfirmed by learn.microsoft.com
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
Security
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fixSecurity
An [Authorize] endpoint rejects a request with a bearer token
Authorization Header sent: no Bearer token sent.
An [Authorize] endpoint without a policy name requires an authenticated user.
4 causes, each with a fixSecurity
ASP.NET Core API rejects an Angular user's token: the signature key was not found
401 Unauthorized
The API looked for the key named by the token's kid in the key set it downloaded from your Authority, and the key was not there.
4 causes, each with a fixSecurity
ASP.NET Core rejects the token before checking it: IDX12741, three segments expected
401 Unauthorized
IDX12741 means the string the API pulled out of the Authorization header is not shaped like a JWT: a signed token has three dot-separated parts and an encrypted one has five.
3 causes, each with a fixSecurity
A Microsoft Entra access token shows Invalid Signature when you check it yourself
Tokens that a Microsoft API receives might not always be a JWT that can be decoded
A token issued for Microsoft Graph is not meant for you to validate, so a failed signature check is expected.
2 causes, each with a fix