Vinit Sawant Thanks for posting your question in Microsoft Q&A. Sorry for the delay in our response. From the description above, you are facing error IDX10511: Signature validation failed. Keys tried 'Microsoft.IdentityModel.Tokens.X509SecurityKey, KeyId: xxxxx
with validate-jwt
policy.
Please follow the solution described in https://techcommunity.microsoft.com/t5/azure-paas-blog/protect-api-s-using-oauth-2-0-in-apim/ba-p/2309538 article and I am posting the summary below for reference:
Solution:
If you look at the metadata for the config url (https://login.microsoftonline.com/common/.well-known/openid-configuration) you will find a jwks_uri property inside the resulting json.
This uri will point to a set of certificates used to sign and validate the jwt's. You may find that the keyId (in this sample "CtTuhMJmD5M7DLdzD2v2x3QKSRY") does exist there.
Something like this:
{
"keys": [{
"kty": "RSA",
"use": "sig",
"kid": "
"x5t": "CtTuhMJmD5M7DLdzD2v2x3QKSRY",
"n": "18uZ3P3IgOySln……",
"e": "AQAB",
"x5c": ["MII….."]
So it seems that it should be able to validate the signature.
If you look at the decoded jwt you may see something like this:
{
"typ": "JWT",
"alg": "RS256",
"x5t": "CtTuhMJmD5M7DLdzD2v2x3QKSRY",
"kid": "CtTuhMJmD5M7DLdzD2v2x3QKSRY"
}
.{
"aud": "00000003-0000-0000-c000-000000000000",
"iss": "[https://sts.windows.net/<tenantID>/](https://sts.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47/)",
"appid": "1950a258-227b-4e31-a9cf-717495945fc2",
**"nonce": "da3d8159-f9f6-4fa8-bbf8-9a2cd108a261",**
There's a nonce in play here.
This requires extra checking that validate-jwt
does not do. Getting a token for the Graph api and Sharepoint may emit a nonce property. A token used to make calls to the Azure management api, however, will not have the nonce property.
The 'nonce' is a mechanism, that allows the receiver to determine if the token was forwarded. The signature is over the transformed nonce and requires special processing, so if you try and validate it directly, the signature validation will fail.
The validate jwt policy is not meant to validate tokens targeted for the Graph api or Sharepoint. The best thing to do here is either remove the validate jwt policy and let the backend service validate it or use a token targeted for a different audience.
So, unfortunately, validate-jwt
policy cannot be used in such scenarios. We do have an open item: https://github.com/MicrosoftDocs/azure-docs/issues/80018 to update the doc and I will follow up with our product team internally to add this note. Sorry for the inconvenience caused.
I hope this helps and let us know if you have any questions.
If you found the answer to your question helpful, please take a moment to mark it as Yes
for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.