I have been tasked with validating AzureAd tokens in an existing API without adding additional dependencies to the project. Is it possible to validate a token by making an http request to azure and passing along the token?
I know that my test configuration that leverages the Microsoft.Identity.Web
package (which I am asked to avoid for the final result), in additional to the ClientId, TenantId, and scopes has the Instance as https://login.microsoftonline.com/, so I assume an underlying http call is being made.
Is there any documentation to show how I could manually build such an http request to validate the token that way?
Thanks!
No, there is no endpoint that does that.
What happens under the hood:
Authority
, for example https://login.microsoftonline.com/common/v2.0
/.well-known/openid-configuration
to the end: https://login.microsoftonline.com/common/v2.0/.well-known/openid-configurationjwks_uri
property of the JSON, for example: https://login.microsoftonline.com/common/discovery/v2.0/keyskid
(key id) in the token header part and finds the matching key from the keys it loaded. Then it's a matter of applying asymmetric cryptography stuff.iss
), validity start time (iat
), expiry time (exp
) + potentially some other thingsaud
) matches this.So the token validation only requires the OpenID Connect metadata + the public signing keys for the key pairs that Azure AD might use to sign tokens. After these are loaded, the app does not need a connection to Azure AD to validate tokens. Usually libraries do reload the metadata and signing keys once in a while, since keys can change at times, though quite rarely.