Hi @Abhay Chandramouli ,
If the application needs to validate an ID token or an access token, it should first validate the signature of the token and the issuer against the values in the OpenID discovery endpoint. You need to get the key from the discovery endpoint and need to check the signature, expiry date, issuer and other related claims.
https://{tenant_name}.b2clogin.com/{tenant_name}.onmicrosoft.com/{signin_policy_name}/v2.0/.well-known/openid-configuration"
There are many SDK available. You can use the sdk System.IdentityModel.Tokens to implement it. For example
var configurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(
"https://{tenant_name}.b2clogin.com/{tenant_name}.onmicrosoft.com/{signin_policy_name}/v2.0/.well-known/openid-configuration?p=B2C_1_test",
new OpenIdConnectConfigurationRetriever(), new HttpDocumentRetriever());
CancellationToken ct = default(CancellationToken);
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
var discoveryDocument = await configurationManager.GetConfigurationAsync(ct);
var signingKeys = discoveryDocument.SigningKeys;
var validationParameters = new TokenValidationParameters
{
RequireExpirationTime = true,
RequireSignedTokens = true,
ValidateIssuer = true,
ValidIssuer = discoveryDocument.Issuer,
ValidateIssuerSigningKey = true,
IssuerSigningKeys = signingKeys,
ValidateLifetime = true,
};
var principal = new JwtSecurityTokenHandler()
.ValidateToken(token, validationParameters, out var rawValidatedToken);
Reference: https://learn.microsoft.com/en-us/azure/active-directory/develop/access-tokens#validate-tokens
Hope this will help.
Thanks,
Shweta