Jem*_*ose 12 c# owin openid-connect
尝试获取访问令牌以在我的 WebApi 中使用 MS Graph。但不断收到这个错误,
[TaskCanceledException: 一个任务被取消。] System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +167。.
[IOException: IDX20804: 无法从以下位置检索文档:'[PII is hidden]'。] Microsoft.IdentityModel.Protocols.d__8.MoveNext() +662 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99。. [InvalidOperationException: IDX20803: 无法从以下位置获取配置:'[PII is hidden]'。] Microsoft.IdentityModel.Protocols.d__24.MoveNext() +1586 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
尝试了我可以在网上找到的所有修复程序。
我使用这个repo作为 auth 部分的参考。
我怎样才能解决这个问题?
Rob*_*ker 24
首先,要解决这个问题,你需要找出错误是什么。在您的中设置此项Startup.cs以揭示真正的错误(不建议用于生产环境):
if (env.IsDevelopment())
{
IdentityModelEventSource.ShowPII = true;
}
Run Code Online (Sandbox Code Playgroud)
就我而言,我在公司网络内本地运行它时遇到了代理问题。
小智 10
我遇到了以下问题
[IOException:IDX20804:无法从以下位置检索文档:“[PII 已隐藏]”。] Microsoft.IdentityModel.Protocols.d__8.MoveNext() +662 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) +99 。。[InvalidOperationException:IDX20803:无法从以下位置获取配置:“[PII 已隐藏]”。] Microsoft.IdentityModel.Protocols.d__24.MoveNext() +1586 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+99
下面的解决方案解决了我的问题。我在startup.cs中添加了以下代码
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
注意:要获取有关异常的详细信息,请添加以下行。您将能够更详细地了解此问题。
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
在创建新的 Blazor 应用程序 -> 使用个人用户帐户的 Blazor 服务器应用程序 -> 连接到云中的现有用户存储 (Azure AD B2C) 时,我遇到了类似的错误。
IOException:IDX20807:无法从以下位置检索文档:“[PII 已隐藏。有关更多详细信息,请参阅https://aka.ms/IdentityModel/PII。] '。HttpResponseMessage: '[PII 已隐藏。有关更多详细信息,请参阅 https://aka.ms/IdentityModel/PII。] ', HttpResponseMessage.Content: '[PII 已隐藏。有关更多详细信息,请参阅 https://aka.ms/IdentityModel/PII。] '。Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(字符串地址,CancellationToken取消)
InvalidOperationException:IDX20803:无法从以下位置获取配置:“[PII 已隐藏。有关更多详细信息,请参阅 https://aka.ms/IdentityModel/PII。] '。Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken 取消)
确保域设置为您的Azure AD B2C域而不是完整App ID URI的appsettings.json. 例如使用<tenant-name>.onmicrosoft.com而不是<tenant-name>.onmicrosoft.com/api. 另请参阅 AzureAdB2C -> 中的实例appsettings.json。我在此处设置了默认值,但当我将其更改为一切都开始工作https://login.microsoftonline.com/tfp时,它不起作用。https://<tenant-name>.b2clogin.com/tfp/
同样在这里,我已阅读以下内容但没有成功。我的设置工作正常,但后来我尝试将其加载到另一台计算机上并遇到此问题。
这是堆栈跟踪,我运行的两个不同应用程序的 http 状态为 400 和 404。
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]'. ---> System.IO.IOException: IDX20804: Unable to retrieve document from: '[PII is hidden]'. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel) --- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel) at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleChallengeAsync(AuthenticationProperties properties)
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.ChallengeAsync(AuthenticationProperties properties)
at Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, String scheme, AuthenticationProperties properties)
at Microsoft.AspNetCore.Mvc.ChallengeResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAlwaysRunResultFilters()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
HIDDEN LINE
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.FeaturePolicy.FeaturePolicyMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.ReferrerPolicy.ReferrerPolicyMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.XContentTypeOptions.XContentTypeOptionsMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.XXssProtection.XXssProtectionMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.XFrameOptions.XFrameOptionsMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.Csp.CspMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Run Code Online (Sandbox Code Playgroud)
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]'. ---> System.IO.IOException: IDX20804: Unable to retrieve document from: '[PII is hidden]'. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel) --- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel) at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
--- End of inner exception stack trace ---
at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleChallengeAsync(AuthenticationProperties properties)
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.ChallengeAsync(AuthenticationProperties properties)
at Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, String scheme, AuthenticationProperties properties)
at Microsoft.AspNetCore.Mvc.ChallengeResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAlwaysRunResultFilters()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Builder.Extensions.MapWhenMiddleware.Invoke(HttpContext context)
HIDDEN LINE
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.FeaturePolicy.FeaturePolicyMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.ReferrerPolicy.ReferrerPolicyMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.XContentTypeOptions.XContentTypeOptionsMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.XXssProtection.XXssProtectionMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.XFrameOptions.XFrameOptionsMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.Csp.CspMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Run Code Online (Sandbox Code Playgroud)
其他讨论此错误的文章。
https://github.com/IdentityServer/IdentityServer4/issues/2337
https://github.com/IdentityServer/IdentityServer4/issues/2672
https://github.com/okta/samples-aspnetcore/issues/10
https://github.com/IdentityServer/IdentityServer4/issues/2186
解决方案:原来我没有在appsettings.json. 我忘记设置我的User Secrets配置 AzureAD 使用有效的凭据。
您需要将以下凭据设置为您自己的 AzureAd 凭据。
{
"AzureAd": {
"TenantId": "SOMETHING.onmicrosoft.com",
"ClientId": "SOMETHING",
"ClientSecret": "SOMETHING"
}
}
Run Code Online (Sandbox Code Playgroud)