【发布时间】:2020-06-19 12:22:58
【问题描述】:
我的应用程序中出现以下基于WebApp-graph-user sample 的错误堆栈。我只是想登录并获取 User.ReadBasic.All 图形权限的令牌。我检查了进入 AcquireTokenByAuthorizationCode 的所有参数,一切看起来都很好(没有空值)。应用是使用 .net core 3.1 的 MVC Web 应用。
堆栈:
NullReferenceException:对象引用未设置为对象的实例。
Microsoft.Identity.Client.Internal.ClientCredentialWrapper.get_Thumbprint()
Microsoft.Identity.Client.Internal.JsonWebToken+JWTHeaderWithCertificate..ctor(ClientCredentialWrapper 凭据,bool sendCertificate)
Microsoft.Identity.Client.Internal.JsonWebToken.EncodeHeaderToJson(ClientCredentialWrapper 凭据,bool sendCertificate)
Microsoft.Identity.Client.Internal.JsonWebToken.Encode(ClientCredentialWrapper 凭据,bool sendCertificate)
Microsoft.Identity.Client.Internal.JsonWebToken.Sign(ClientCredentialWrapper 凭据,bool sendCertificate)
Microsoft.Identity.Client.Internal.Requests.ClientCredentialHelper.CreateClientCredentialBodyParameters(ICoreLogger 记录器,ICryptographyManager cryptographyManager,ClientCredentialWrapper clientCredential,字符串 clientId,AuthorityEndpoints 端点,bool sendX5C)
Microsoft.Identity.Client.OAuth2.TokenClient.SendTokenRequestAsync(IDictionary additionalBodyParameters,字符串 scopeOverride,字符串 tokenEndpointOverride,CancellationToken cancelToken)
Microsoft.Identity.Client.Internal.Requests.RequestBase.SendTokenRequestAsync(字符串 tokenEndpoint,IDictionary additionalBodyParameters,CancellationToken cancelToken)
Microsoft.Identity.Client.Internal.Requests.ConfidentialAuthCodeRequest.ExecuteAsync(CancellationToken cancelToken)
Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancelToken)
Microsoft.Identity.Client.ApiConfig.Executors.ConfidentialClientExecutor.ExecuteAsync(AcquireTokenCommonParameters commonParameters,AcquireTokenByAuthorizationCodeParameters authorizationCodeParameters,CancellationToken cancelToken)
TokenAcquisition.cs 中的 Microsoft.Identity.Web.TokenAcquisition.AddAccountToCacheFromAuthorizationCodeAsync(AuthorizationCodeReceivedContext context, IEnumerable scopes)
+
var 结果 = 等待申请
WebAppServiceCollectionExtensions.cs 中的 Microsoft.Identity.Web.WebAppServiceCollectionExtensions+c__DisplayClass2_1+
代码: 来自 TokenAcquisition.cs - 第 127 行
// Do not share the access token with ASP.NET Core otherwise ASP.NET will cache it and will not send the OAuth 2.0 request in
// case a further call to AcquireTokenByAuthorizationCodeAsync in the future is required for incremental consent (getting a code requesting more scopes)
// Share the ID Token though
var result = await application
.AcquireTokenByAuthorizationCode(scopes.Except(_scopesRequestedByMsal), context.ProtocolMessage.Code)
.ExecuteAsync()
.ConfigureAwait(false);
context.HandleCodeRedemption(null, result.IdToken);
【问题讨论】:
标签: microsoft-graph-api microsoft-identity-platform