我正在尝试创建一个使用MSAL作为客户端凭据流的ASP.NET Core应用程序。
尝试获取访问令牌时出现以下异常:
NullReferenceException: Object reference not set to an instance of an object.
Microsoft.Identity.Client.Internal.PlatformPlugin.LoadPlatformSpecificAssembly()
验证是在此示例之后建模的:active-directory-dotnet-webapp-openidconnect-aspnetcore-v2
在此示例之后模拟授权:active-directory-dotnet-daemon-v2
我的应用已使用Mail.Read应用程序权限注册。这是抛出异常的代码:
string authority = $"https://login.microsoftonline.com/{ tenantId }/v2.0";
ConfidentialClientApplication client = new ConfidentialClientApplication(
authority,
appId,
redirectUri,
new ClientCredential(appSecret),
null);//new TokenCache());
AuthenticationResult authResult = await client.AcquireTokenForClient(
new string[] { "Mail.Read" }, null);
return authResult.Token;
还尝试使用“https://graph.microsoft.com/.default”范围,如守护程序示例中那样。