How to fix Signature validation failed when trying to validate an access token of Microsoft Entra ID

Bernardo Garza García 10 Reputation points
2024-06-07T20:44:34.87+00:00

Hi,

I'm trying to validate my access token signature from Microsoft Entra ID, as you can see in the below image, the "kid" attribute is different from the keys retrieved in the second image below that were retrieved from [domain+tenant]/.well-known/openid-configuration

This is causing the next error: The token's kid is: 'f0GUng0wL6zx4dx1Iuu1ForRHEA', but did not match any keys in TokenValidationParameters 

Could you try to help me to understand if I am doing something wrong ? This only happens with Microsoft Entra ID, it works when using Azure AD B2C

Image preview

Image preview

StackTrace:

HResult=0x80131500

  Message=IDX10503: Signature validation failed. The token's kid is: 'f0GUng0wL6zx4dx1Iuu1ForRHEA', but did not match any keys in TokenValidationParameters or Configuration. Keys tried: 'Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: 'q-23falevZhhD3hm9CQbkP5MQyU', InternalId: 'q-23falevZhhD3hm9CQbkP5MQyU'. , KeyId: q-23falevZhhD3hm9CQbkP5MQyU

Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: 'q-23falevZhhD3hm9CQbkP5MQyU', InternalId: 'S_S12adpbe27-_qkluYZHCSMRJ6EcrW5Ho4cyLGEjG8'. , KeyId: q-23falevZhhD3hm9CQbkP5MQyU

Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: 'V1Y09OFMBXAZUFfJ-vWjlrH-ZSc', InternalId: 'V1Y09OFMBXAZUFfJ-vWjlrH-ZSc'. , KeyId: V1Y09OFMBXAZUFfJ-vWjlrH-ZSc

Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: 'V1Y09OFMBXAZUFfJ-vWjlrH-ZSc', InternalId: '21yYN7-15_HEG6Myr8mw1D07vAMCN503j4n1GnsWWJQ'. , KeyId: V1Y09OFMBXAZUFfJ-vWjlrH-ZSc

Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: 'L1KfKFI_jnXbwWc22xZxw1sUHH0', InternalId: 'L1KfKFI_jnXbwWc22xZxw1sUHH0'. , KeyId: L1KfKFI_jnXbwWc22xZxw1sUHH0

Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: 'L1KfKFI_jnXbwWc22xZxw1sUHH0', InternalId: 'RlwaR9qe84mGeeFWVsLX3zezPkY88aZiSkDuuqUxftM'. , KeyId: L1KfKFI_jnXbwWc22xZxw1sUHH0

Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: 'UxyGE-ffaoAkooUxUFn0ar7fvDM', InternalId: 'UxyGE-ffaoAkooUxUFn0ar7fvDM'. , KeyId: UxyGE-ffaoAkooUxUFn0ar7fvDM

Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: 'UxyGE-ffaoAkooUxUFn0ar7fvDM', InternalId: 'IC5xpkooVq3LolG30n_19Ollz-mDTXlIuq4MdlmjwFE'. , KeyId: UxyGE-ffaoAkooUxUFn0ar7fvDM

Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: 'EHu9neGZBCDyv2IYq8U5JiRMFng', InternalId: 'EHu9neGZBCDyv2IYq8U5JiRMFng'. , KeyId: EHu9neGZBCDyv2IYq8U5JiRMFng

Microsoft.IdentityModel.Tokens.RsaSecurityKey, KeyId: 'EHu9neGZBCDyv2IYq8U5JiRMFng', InternalId: '4xRadtB97YyM0GXtJGF1MHO11LmoVHRCXd4Gp3tNb6Y'. , KeyId: EHu9neGZBCDyv2IYq8U5JiRMFng

'. Number of keys in TokenValidationParameters: '10'. 

Microsoft Security Microsoft Entra Microsoft Entra ID
Developer technologies .NET Other
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. James Hamil 27,211 Reputation points Microsoft Employee Moderator
    2024-06-10T20:30:33.37+00:00

    Hi @Bernardo Garza García , can you please try the following for me?

    1. Check if the authority that issued the token is the same as the one you are trying to validate against. You can do this by comparing the "iss" claim in the token with the authority's URL.
    2. Check if the signing keys have been updated since the token was issued. You can retrieve the latest signing keys from the OpenID configuration endpoint and compare them with the "kid" attribute in the token. If they are different, you can update your validation logic to use the latest signing keys.
    3. If you are still having issues, you can try enabling the "RefreshOnIssuerKeyNotFound" option in your validation logic. This will force the validation logic to retrieve the latest signing keys from the OpenID configuration endpoint if the "kid" attribute in the token does not match any of the cached keys.

    Please let me know your results and I can help you further.

    Best,

    James

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.