我遵循了以下教程 Azure AD B2C: Call an ASP.NET Web API from an ASP.NET Web App
我可以运行该应用。
收到授权码后,我在第var code = notification.Code;
行设置了一个断点,我可以看到收到的所有索赔。
但是当我尝试打印声明时,不会显示任何内容并且应用程序退出。它在以下行显示空对象引用
string a = notification.AuthenticationTicket.Identity.FindFirst(ClaimTypes.Country).Value;
知道如何打印所有索赔。任何帮助将不胜感激。谢谢
private async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedNotification notification)
{
// Extract the code from the response notification
var code = notification.Code;
string signedInUserID = notification.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
string a = notification.AuthenticationTicket.Identity.FindFirst(ClaimTypes.Country).Value;
TokenCache userTokenCache = new MSALSessionCache(signedInUserID, notification.OwinContext.Environment["System.Web.HttpContextBase"] as HttpContextBase).GetMsalCacheInstance();
ConfidentialClientApplication cca = new ConfidentialClientApplication(ClientId, Authority, RedirectUri, new ClientCredential(ClientSecret), userTokenCache, null);
try
{
AuthenticationResult result = await cca.AcquireTokenByAuthorizationCodeAsync(code, Scopes);
}
catch (Exception ex)
{
//TODO: Handle
throw;
}
}