I'm using the code below in a Net Core WebApi app and it's working well.
I can decode the JWT that it produces, but I would also like to verify it's signature. But, where do I get the key to verify it with?
tenant = Configuration.GetSection("AzureAD:Tenant").Value;
Logger.AppLogDebug("tenat value found: [{0}]", tenant);
azureAdInstance = Configuration.GetSection("AzureAD:AzureADInstance").Value;
Logger.AppLogDebug("azureAdInstance value found: [{0}]", azureAdInstance);
audience = Configuration.GetSection("AzureAD:Audience").Value;
Logger.AppLogDebug("Audience value found: [{0}]", audience);
var authority = $"{azureAdInstance}{tenant}";
Logger.AppLogDebug("authority value set to: [{0}]", authority);
var authContext = new AuthenticationContext(authority);
var clientCredential = new ClientCredential(key, secret);
var token = authContext.AcquireTokenAsync(audience, clientCredential).Result.AccessToken;
return new ObjectResult($"Bearer {token}");