skip to Main Content

I have created an app Registration and want to add some custom claims into my JWT access token.
I have follow the instructions from https://learn.microsoft.com/en-us/entra/identity-platform/optional-claims but somehow I must have done a mistake as I cannot get any additional claim into my JWT access token (I request it via Postman and check the data with https://jwt.io).

I tried to add the custom claims via the azure portal but my JWT does not add these values
I played with the scopes and used: User.Read openid profile but changing these value did not change anything too.

Her the example of my manifest:

{
    "id": "cfdb05a2-357b-4e52-8f68-7a4a48a45256",
    "acceptMappedClaims": null,
    "accessTokenAcceptedVersion": 2,
    "addIns": [],
    "allowPublicClient": true,
    "appId": "19eccd56-b192-450d-820c-77a353d1fd7c",
    "appRoles": [],
    "oauth2AllowUrlPathMatching": false,
    "createdDateTime": "2024-04-22T14:31:19Z",
    "description": null,
    "certification": null,
    "disabledByMicrosoftStatus": null,
    "groupMembershipClaims": "None",
    "identifierUris": [
        "api://19eccd56-b192-450d-820c-77a353d1fd7c"
    ],
    "informationalUrls": {
        "termsOfService": null,
        "support": null,
        "privacy": null,
        "marketing": null
    },
    "keyCredentials": [],
    "knownClientApplications": [],
    "logoUrl": null,
    "logoutUrl": null,
    "name": "TEST_APP_SAML",
    "notes": null,
    "oauth2AllowIdTokenImplicitFlow": true,
    "oauth2AllowImplicitFlow": true,
    "oauth2Permissions": [],
    "oauth2RequirePostResponse": false,
    "optionalClaims": {
        "idToken": [
            {
                "name": "tenant_region_scope",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "verified_primary_email",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "verified_secondary_email",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "vnet",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "ctry",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "tenant_ctry",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "xms_pdl",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "xms_pl",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "xms_tpl",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "ztdid",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "upn",
                "source": null,
                "essential": false,
                "additionalProperties": [
                    "include_externally_authenticated_upn"
                ]
            },
            {
                "name": "xms_cc",
                "source": null,
                "essential": false,
                "additionalProperties": []
            }
        ],
        "accessToken": [
            {
                "name": "ctry",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "tenant_ctry",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "ztdid",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "upn",
                "source": null,
                "essential": false,
                "additionalProperties": [
                    "include_externally_authenticated_upn"
                ]
            },
            {
                "name": "login_hint",
                "source": null,
                "essential": false,
                "additionalProperties": []
            }
        ],
        "saml2Token": []
    },
    "orgRestrictions": [],
    "parentalControlSettings": {
        "countriesBlockedForMinors": [],
        "legalAgeGroupRule": "Allow"
    },
    "passwordCredentials": [],
    "preAuthorizedApplications": [],
    "publisherDomain": "andreasweier85gmail.onmicrosoft.com",
    "replyUrlsWithType": [
        {
            "url": "https://jwt.ms",
            "type": "InstalledClient"
        },
        {
            "url": "https://login.microsoftonline.com/common/oauth2/nativeclient",
            "type": "InstalledClient"
        }
    ],
    "requiredResourceAccess": [
        {
            "resourceAppId": "00000003-0000-0000-c000-000000000000",
            "resourceAccess": [
                {
                    "id": "14dad69e-099b-42c9-810b-d002981feec1",
                    "type": "Scope"
                },
                {
                    "id": "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
                    "type": "Scope"
                }
            ]
        },
        {
            "resourceAppId": "00eda80b-051a-46ab-940f-2bbdc3dabeec",
            "resourceAccess": [
                {
                    "id": "4d2e19f0-3525-4517-9e7d-48f0411b4395",
                    "type": "Scope"
                }
            ]
        }
    ],
    "samlMetadataUrl": null,
    "signInUrl": null,
    "signInAudience": "AzureADMultipleOrgs",
    "tags": [
        "apiConsumer",
        "singlePageApp"
    ],
    "tokenEncryptionKeyId": null
}

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for the answer. Somehow I do still not manage to get the values in my token even with your proposed solution.

    I did some investigations/tries and found out, that if I add in my scope openid (in order to use openid eg. get Id token) then I get all my needed values (groups, custom claims, standard claims ) in the id token but not in the access token. Any further hints?

    Here once again my config and an example ID-TOKen and Access-Token I get

    Manifest:

    {
    "id": "d0315962-fdd0-4e9e-a037-fe387f26b206",
    "acceptMappedClaims": true,
    "accessTokenAcceptedVersion": null,
    "addIns": [],
    "allowPublicClient": true,
    "appId": "00eda80b-051a-46ab-940f-2bbdc3dabeec",
    "appRoles": [
        {
            "allowedMemberTypes": [
                "User"
            ],
            "description": "EOS_INTERNAL_API_TEST_VIEWER",
            "displayName": "EOS_INTERNAL_API_TEST_VIEWER",
            "id": "d3156009-3dce-4656-bc88-39da2f836a74",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "value": "EOS_INTERNAL_API_TEST_VIEWER"
        },
        {
            "allowedMemberTypes": [
                "User"
            ],
            "description": "Allow to edit equipments",
            "displayName": "E COMMISSIONING USER",
            "id": "8aaeaebe-df7b-43af-9e29-c6690529ea16",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "value": "E_COMMISSIONING_USER"
        },
        {
            "allowedMemberTypes": [
                "User"
            ],
            "description": "Gives access to EOS Appp and role",
            "displayName": "EOS CLOUD API READER",
            "id": "8af325ba-8952-4e90-994b-b1bf2e109463",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "value": "EOS_CLOUD_API_READER"
        }
    ],
    "oauth2AllowUrlPathMatching": false,
    "createdDateTime": "2024-04-22T08:22:20Z",
    "description": null,
    "certification": null,
    "disabledByMicrosoftStatus": null,
    "groupMembershipClaims": "SecurityGroup",
    "identifierUris": [
        "api://00eda80b-051a-46ab-940f-2bbdc3dabeec"
    ],
    "informationalUrls": {
        "termsOfService": null,
        "support": null,
        "privacy": null,
        "marketing": null
    },
    "keyCredentials": [],
    "knownClientApplications": [],
    "logoUrl": null,
    "logoutUrl": null,
    "name": "TEST_APP_OIDC",
    "notes": null,
    "oauth2AllowIdTokenImplicitFlow": true,
    "oauth2AllowImplicitFlow": true,
    "oauth2Permissions": [
        {
            "adminConsentDescription": "access_as_a_user to internal services",
            "adminConsentDisplayName": "access_as_a_user",
            "id": "4d2e19f0-3525-4517-9e7d-48f0411b4395",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "type": "Admin",
            "userConsentDescription": null,
            "userConsentDisplayName": null,
            "value": "access_as_a_user"
        }
    ],
    "oauth2RequirePostResponse": false,
    "optionalClaims": {
        "idToken": [
            {
                "name": "tenant_ctry",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "groups",
                "source": null,
                "essential": false,
                "additionalProperties": [
                    "emit_as_roles"
                ]
            }
        ],
        "accessToken": [
            {
                "name": "tenant_ctry",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "groups",
                "source": null,
                "essential": false,
                "additionalProperties": [
                    "emit_as_roles"
                ]
            }
        ],
        "saml2Token": [
            {
                "name": "groups",
                "source": null,
                "essential": false,
                "additionalProperties": []
            }
        ]
    },
    "orgRestrictions": [],
    "parentalControlSettings": {
        "countriesBlockedForMinors": [],
        "legalAgeGroupRule": "Allow"
    },
    "passwordCredentials": [],
    "preAuthorizedApplications": [],
    "publisherDomain": "andreasweier85gmail.onmicrosoft.com",
    "replyUrlsWithType": [
        {
            "url": "msal00eda80b-051a-46ab-940f-2bbdc3dabeec://auth",
            "type": "InstalledClient"
        },
        {
            "url": "com.schindler.ecommissioning.dev://auth",
            "type": "InstalledClient"
        }
    ],
    "requiredResourceAccess": [
        {
            "resourceAppId": "00000003-0000-0000-c000-000000000000",
            "resourceAccess": [
                {
                    "id": "37f7f235-527c-4136-accd-4a02d197296e",
                    "type": "Scope"
                },
                {
                    "id": "14dad69e-099b-42c9-810b-d002981feec1",
                    "type": "Scope"
                },
                {
                    "id": "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
                    "type": "Scope"
                }
            ]
        },
        {
            "resourceAppId": "00eda80b-051a-46ab-940f-2bbdc3dabeec",
            "resourceAccess": [
                {
                    "id": "4d2e19f0-3525-4517-9e7d-48f0411b4395",
                    "type": "Scope"
                }
            ]
        }
    ],
    "samlMetadataUrl": null,
    "signInUrl": null,
    "signInAudience": "AzureADMyOrg",
    "tags": [
        "mobileApp",
        "apiConsumer"
    ],
    "tokenEncryptionKeyId": null
    

    }

    The ID-Token:

        {
      "aud": "00eda80b-051a-46ab-940f-2bbdc3dabeec",
      "iss": "https://login.microsoftonline.com/dfbe9256-6a2f-462d-b167-551e7820bbf5/v2.0",
      "iat": 1714140486,
      "nbf": 1714140486,
      "exp": 1714144386,
      "ageGroup": "3",
      "aio": "AWQAm/8WAAAAuH6xNGD/vyZAmCGnPjMW3s7fVufR/eVxhtEmg+gwvWO0priGvbGHyGIF7WZGGUnqYo/KPxNWPfANDTVLXed90AKRSS/P/c8vGW+E5DJIUXek3893aKmEoudiTC64jkCf",
      "name": "John Doe",
      "oid": "eacfc81d-bd8f-427a-8d0f-bb196489f5df",
      "preferred_username": "[email protected]",
      "rh": "0.AU4AVpK-3y9qLUaxZ1UeeCC79Quo7QAaBatGlA8rvcPavuyDAEw.",
      "roles": [
        "3e048c38-ec28-4a38-9f37-b980defc1013"
      ],
      "sub": "u0X91VMHBi-c5xnlmT2h4AuGE3t6NXgqhBNmidO23Dc",
      "tid": "dfbe9256-6a2f-462d-b167-551e7820bbf5",
      "uti": "zYCWTquBzka8LJe5W2fVAQ",
      "ver": "2.0",
      "optionalClaims/CompanyName": "NoCompany",
      "optionalClaims/EmployeeID": "356986",
      "optionalClaims/Departement": "Department"
    }
    

    and finaly the access token (decoded payload):

      {
      "aud": "00000003-0000-0000-c000-000000000000",
      "iss": "https://sts.windows.net/dfbe9256-6a2f-462d-b167-551e7820bbf5/",
      "iat": 1714142950,
      "nbf": 1714142950,
      "exp": 1714146892,
      "acct": 0,
      "acr": "1",
      "ageGroup": "3",
      "aio": "ATQAy/8WAAAATGB+js/mbmdvrIiGThmK6J7AQzt0XlEeO3Q7JvJC+8D9/fZfP+KcfCeqV2Ag3Xyl",
      "amr": [
        "pwd"
      ],
      "app_displayname": "TEST_APP_OIDC",
      "appid": "00eda80b-051a-46ab-940f-2bbdc3dabeec",
      "appidacr": "0",
      "idtyp": "user",
      "ipaddr": "195.65.184.253",
      "name": "John Doe",
      "oid": "eacfc81d-bd8f-427a-8d0f-bb196489f5df",
      "platf": "5",
      "puid": "10032003757AF43C",
      "rh": "0.AU4AVpK-3y9qLUaxZ1UeeCC79QMAAAAAAAAAwAAAAAAAAACDAEw.",
      "scp": "openid profile User.Read email",
      "sub": "dn0pam9j_n1_o_kn_5ttM6cmnjmnzkdFcht5wHZSbSE",
      "tenant_region_scope": "EU",
      "tid": "dfbe9256-6a2f-462d-b167-551e7820bbf5",
      "unique_name": "[email protected]",
      "upn": "[email protected]",
      "uti": "yJVJS_xlHEi4eRz7MjYDAA",
      "ver": "1.0",
      "wids": [
        "b79fbf4d-3ef9-4689-8143-76b194e85509"
      ],
      "xms_st": {
        "sub": "u0X91VMHBi-c5xnlmT2h4AuGE3t6NXgqhBNmidO23Dc"
      },
      "xms_tcdt": 1677362146,
      "xms_tdbr": "EU"
    }
    

  2. In your optional claims you have not specified a source. When source is null the Microsoft Identity Platform doesn’t know where to get the information from. Thus, the claim is completely omitted from the token.

    name: The name of the claim as it will apear in the token returned by the Identity Platform.

    source: The Entra ID User Profile Attribute, or Directory Extension, which should be read for the authenticating user. You can use OOB attributes, such as userPrincipalName. Or, you can use an extended (custom) attribute. For custom attributes, such as your use of vnet, you should have already extended the directory schema and assigned a value to the user.

    essential: Tells the server to fail authentication if it is not possible to obtain the value of source for the user. You’ve set to false, which is fine.

    additionalProperties: Allows you to validate, filter and transform the claim value according to criteria, conditions, and parameters you specify. include_externally_authenticated_upn does not appear to me to be a valid additional property field.

    So, let’s look at an example where you want to return the user principal name as a claim with the name upn.

                  {
                    "name": "upn",
                    "source": "userPrincpalName",
                    "essential": false,
                    "additionalProperties": []
                  }
    

    Here we use name "upn" to specify the return claim name, and source userPrincipalName, because that is the name of the attribute in Entra.

    If you are using custom attributes from a directory extension, make sure the extension has been applied.

    https://learn.microsoft.com/en-us/entra/identity/domain-services/concepts-custom-attributes

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search