Created
December 16, 2021 12:35
-
-
Save watahani/f0da92092c0fbe47bbfb9f96c0265734 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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