【问题标题】:Getting error when requesting graph permissions through Microsoft.Identity.Web通过 Microsoft.Identity.Web 请求图形权限时出错
【发布时间】: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+d.MoveNext() + 等待 tokenAcquisition.AddAccountToCacheFromAuthorizationCodeAsync(context, options.Scope).ConfigureAwait(false); Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.RunAuthorizationCodeReceivedEventAsync(OpenIdConnectMessage 授权响应,ClaimsPrincipal 用户,AuthenticationProperties 属性,JwtSecurityToken jwt) Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleRemoteAuthenticateAsync()

代码: 来自 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


    【解决方案1】:

    已解决:由于此处讨论的错误配置,这结果是一个空客户端密码值:https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/1476

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-31
      • 2021-06-27
      • 2022-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多