question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation is unclear about TokenValidationParameters.ValidateIssuerSigningKey

See original GitHub issue

Opened at https://github.com/dotnet/core/issues/5877 by @marwalsch

I am setting up Basic AuthN for a JWT issued by the Windows STS. However, I am unsure about the correct way to do so and the Documentations are somewhat lacky about the correct way. These are my AddJwtBearer -options and the simplified Token:

options.TokenValidationParameters = new TokenValidationParameters  
                    {
                        ValidateIssuer = true,
                        ValidIssuer = "https://sts.windows.net/tenant/", 

                        ValidateAudience = true, 
                        ValidAudience = "api://domain.ngrok.io/resource",

                        ValidateIssuerSigningKey = true, 


                        ValidateLifetime = true
                    };
                    options.Audience = "api://domain.ngrok.io/resource";
                    options.Authority = "https://sts.windows.net/tenant/";
{
  "typ": "JWT",
  "alg": "RS256",
  "x5t": "nOo3ZDrODXEK1jKWhXslHR_KXEg",
  "kid": "nOo3ZDrODXEK1jKWhXslHR_KXEg"
}
{
  "aud": "api://domain.ngrok.io/resource",
  "iss": "https://sts.windows.net/tenant/",
  "iat": 1611134241,
  "nbf": 1611134241,
  "exp": 1611141741,
}
{<SIGNATURE>}

Validation works as far as to deprecated Tokens or those lacking a signature partition entirely being rejected. I am unsure about the most important step though, namely the Signature-Validation. The docs have these description for the cirresponding parameters:

Authority: “Gets or sets the Authority to use when making OpenIdConnect calls.” ValidateIssuerSigningKey: “Gets or sets a boolean that controls if validation of the SecurityKey that signed the securityToken is called. It is possible for tokens to contain the public key needed to check the signature. For example, X509Data can be hydrated into an X509Certificate, which can be used to validate the signature. In these cases it is important to validate the SigningKey that was used to validate the signature. This boolean only applies to default signing key validation. If IssuerSigningKeyValidator is set, it will be called regardless of whether this property is true or false.” (Link to the docs)

This sounds like the Middleware uses the Authority (“https://sts.windows.net/tenant/”) to retrieve the public key from the Windows STS and check the signature through the given alg-Parameter (RS256 in this case).

Is this correct? Or am I lacking additional configuration to achieve the desired? Many samples have an additional parameter passed to ValidIssuerSigninKey but i suppose this is unnecessary if my Token hails from the STS and not my own implementation.

EDIT: I am referring to .NET Core 3.1


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
marwalschcommented, Jan 29, 2021

@brentschmaltz Thanks but unfortunately, this description still doesn’t answer my question to full extend. It states: “Normally this is not required because the user / runtime must set IssuerSigningKey or IssuerSigningKeys or in the case of custom security key retrieval the delegate IssuerSigningKeyResolver […]”. But am I required to set a signing key? My token hails from Azure AD itself after all, and I expected the middleware to retrieve it by default. Please refer to this extract from my original question: “[…] am I lacking additional configuration to achieve the desired? Many samples have an additional parameter passed to ValidIssuerSigninKey but i suppose this is unnecessary if my Token hails from the STS and not my own implementation.”

With my current configuration, tokens that have a removed signature or some Base64-gibberish replacing it are rejected, but obviously I want to make sure that the actual signature is checked against with the public key correctly.

@jsquire Please re-open if necessary.

0reactions
marwalschcommented, Jun 20, 2022

@allysonjoses Don’t quote me on that, but I’m am almost 100% sure that

  • TokenValidationParameters.ValidIssuer merely checks for string equality;
  • JwtBearerOptions.Authority actually does an OIDC compliant call to the well-known endpoint to validate the signature.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation is unclear about TokenValidationParameters ...
ValidateIssuerSigningKey : "Gets or sets a boolean that controls if validation of the SecurityKey that signed the securityToken is called. It is ...
Read more >
Is it necessary to set ValidateIssuerSigningKey to true ...
I am using AspNet Core to build a web api and JWT tokens to authenticate users. I see that in TokenValidationParameters the default...
Read more >
TokenValidationParameters.ValidateIssuerSigningKey ...
Gets or sets a boolean that controls if validation of the SecurityKey that signed the securityToken is called.
Read more >
ASP.NET Core Api Auth with multiple Identity Providers
This article shows how an ASP.NET Core API can be secured using multiple access tokens from different identity providers. ASP.
Read more >
Configure Auth0 API App to accept id_token instead of ...
The Client Secret from the corresponding application seems to come up as valid though, which is confusing if I'm hitting my API that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found