我正在尝试创建一个将 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 ”范围,如在守护程序示例中。