When setting up JWT Bearer token validation, I came across a behavior that I could not find documented anywhere.
.NET Core 3 Web API
Only issuers listed as ValidIssuers are allowed to access the API.
services
.AddAuthentication()
.AddJwtBearer(options =>
{
options.Audience = /* clientID */;
options.Authority = /* authority */;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuers = new[] { /* list of valid issuers */ },
ValidateIssuer = true,
ValidAudiences = new[] { /* list of valid audiences */},
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
};
});
An additional validator is included in the ValidIssuers list in the JWTBearerHandler implementation. Thus, the list of ValidIssuers that I provided is not the final list of ValidIssuers that is used for the comparison.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@ccowden, Thank you for sharing this finding. This is something that I see missing in our documentation. Allow us some time to figure out how we can update our docs with this information.
@hpsin, It would be great if you can check on this thread and update the document accordingly.
This is a library question, not a protocols question. @jmprieur would be the appropriate contact here.
@souravmishra-msft : this can be the union of Issuer and ValidIssuer.
@k8edev: this is handled in Microsoft.Identity.Web: See https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web/Resource/AadIssuerValidator.cs.
Also added details to the https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-protected-web-api-app-configuration#token-validation article
See https://github.com/MicrosoftDocs/azure-docs-pr/pull/122459
Fixed by https://github.com/MicrosoftDocs/azure-docs-pr/pull/122459
should be online soon