Skip to content

Instantly share code, notes, and snippets.

@watahani
Created December 16, 2021 12:35
Show Gist options
  • Save watahani/f0da92092c0fbe47bbfb9f96c0265734 to your computer and use it in GitHub Desktop.
Save watahani/f0da92092c0fbe47bbfb9f96c0265734 to your computer and use it in GitHub Desktop.
using Microsoft.IdentityModel.Tokens;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Protocols;
// See https://aka.ms/new-console-template for more information
var token = Console.ReadLine();
var configManager = new ConfigurationManager<OpenIdConnectConfiguration>("https://login.microsoftonline.com/69191dcf-9be5-47ba-9010-b356d335a6e4/v2.0/.well-known/openid-configuration", new OpenIdConnectConfigurationRetriever());
var parameters = new TokenValidationParameters()
{
ConfigurationManager = configManager,
ValidAudience = "76a28491-ce24-459b-937a-a61de673c1ca"
};
var handler = new JsonWebTokenHandler();
try
{
var result = handler.ValidateToken(token, parameters);
Console.WriteLine(result.IsValid);
foreach (var claim in result.Claims)
{
System.Console.WriteLine($"{claim.Key}: {claim.Value}");
}
}
catch (SecurityTokenException e)
{
System.Console.WriteLine(e.Message);
throw;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment