You can use the OnTokenValidated event to capture the token for debugging.
Here is a sample code from Startup.cs
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
services.Configure(AzureADDefaults.OpenIdScheme, options =>
{
options.Authority = options.Authority + "/v2.0/";
options.TokenValidationParameters.ValidateIssuer = false;
options.Events = new OpenIdConnectEvents
{
OnTokenValidated = context =>
{
// Access Token
var accessToken = context.SecurityToken.RawData;
return Task.CompletedTask;
},
OnAuthenticationFailed = context =>
{
Console.WriteLine($"Token Authentication failed with error: " + context.Exception.Message);
return Task.CompletedTask;
}
};
});