尝试获取访问令牌以在WebApi中使用MS Graph。但是,请继续获取此错误,
[TaskCanceledException:任务已取消。] System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+167。
[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
尝试了我可以在网上找到的所有修补程序。
我正在将此repo用作auth部分的参考。
我该如何解决?
答案 0 :(得分:2)
在创建新的Blazor应用程序->具有个人用户帐户的Blazor Server应用程序时->连接到云中的现有用户存储区(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(string 地址,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
。还要查看appsettings.json
中的AzureAdB2C->实例。我在此处将值https://login.microsoftonline.com/tfp
设置为默认值,但是它不起作用,当我将其更改为https://<tenant-name>.b2clogin.com/tfp/
时,一切开始起作用。
答案 1 :(得分:0)
与此处相同,我没有仔细阅读以下内容。我的设置正常运行,但是随后我试图将其加载到另一台计算机上,并且遇到了这个问题。
这是堆栈跟踪,对于正在运行的两个不同应用程序,我的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)
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)
其他讨论此错误的文章。
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
中配置AzureAD。我忘记设置User Secrets
来配置具有有效凭据的AzureAD。
您将需要为AzureAd设置以下凭据。
{
"AzureAd": {
"TenantId": "SOMETHING.onmicrosoft.com",
"ClientId": "SOMETHING",
"ClientSecret": "SOMETHING"
}
}
答案 2 :(得分:0)
我遇到了同样的问题,这是因为它必须通过DockerNAT。 (可能不是每个人都获得此IP地址)
这是我解决问题的方式:
您将得到类似的东西。
Windows IP配置
以太网适配器vEthernet(DockerNAT):
特定于连接的DNS后缀。 :
IPv4地址。 。 。 。 。 。 。 。 。 。 。 : 10.0.75.1
子网掩码。 。 。 。 。 。 。 。 。 。 。 :255.255.255.240
默认网关。 。 。 。 。 。 。 。 。 :
基本上将该IP地址复制到docker-compose.yml文件
服务:
webmvc:
build:
context: .\src\Web\WebMvc
dockerfile: Dockerfile
environment:
- IdentityUrl=http://10.0.75.1:5000/ #Change IP and Port
container_name: test
ports:
- "5200:80"
networks:
- frontend
depends_on:
- tokenserver #your identityserver4 service
其他要检查的内容是:
请确保在Startup.cs上的ConfigureServices(WebMvc项目)下,您具有以下内容,并且在yml文件中它们的拼写正确。
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options => {
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = identityUrl.ToString();
options.SignedOutRedirectUri = "http://localhost:5200/"; //Change to your mvc address
options.ClientId ="mvc";
options.ClientSecret = "secret";
options.ResponseType = "code id_token";
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.RequireHttpsMetadata = false;
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("offline_access");
options.TokenValidationParameters = new TokenValidationParameters()
{
NameClaimType = "name",
RoleClaimType = "role"
};
});
a。打开控制面板
b。系统与安全性
c。 Windows Defender防火墙
d。高级设置e。入站设置=>新规则。
f。规则类型=>端口==>单击下一步
g在协议下选择TCP
h。特定的本地端口=>输入5000
i。单击下一步=>选择允许连接
j。点击下一步
k。我在“规则何时适用?”下保留了所有选中项。
l。单击下一步=>输入Docker端口=>单击完成