IDX20804: Unable to retrieve document from: '[PII is hidden]'
Hi,
I have a problem with IdentityServer4 and my API running as an Azure container instance. My IdentityServer4 and the the secured API runs locally in a Docker container without problems.
As soon as I run the Docker Container as an Azure Container instance I get the following error. Authentication works without problems (Login). But as soon as I call my Web API with a valid Bearer Token I get the following error.
Runtime: .NET Core 2.1-rc1 IdentityServer4-2.2.0
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: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
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.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler.HandleAuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIIndexMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext)
As I said, Local in Docker works without any problems. Has anyone ever had the following problem or does anyone know a solution?
Regards & Thanks Robert
Which flow are you using? Is authentication local or with Azure AD?
I‘m using only local auth with username and password. The authentication from User with login/password works fine. The Issue comes later, when the API try to validate the Token by the IdentityServer.
This error is caused by your API being unable to load the OpenID Discovery Document (/.well-known/openid-configuration)
All set on this issue -- can we close?
No. You can't close it. I have the exact same issue in the exact same scenario, except I'm not using a Docker Container. Application works just great on a dev server running the Azure simulator, but fails when published.
You say the error is caused by the API not being able to load an OpenID Discovery document, like I'm supposed to understand what that is or how to fix it. Please provide some more detail.
If I dig a little further into the Exception information that's returned to the client, I get this as the root cause:
Could not load type 'System.FormattableString' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Here, too, the problem still exists. Local docker environment everything fine. Once it runs in Azure Container Instances there is the problem. I wanted to try it today in AKS and see how it behaves there. Unfortunately I have no starting point for a solution. The configuration endpoint of the IdentityServer is publicly available. I can only imagine that Azure Container Instances does not allow routes that contains a dot 🤔
Same issue here :( Has anyone found a solution? It looks like the endpoint using the Identity Server Authentication doesn't find the configuration. Any workarounds?
Same problem here without any Docker or Azure. I get this error with IdSrv4 using secured Web.API to retrieve its configuration data from database during introspection. At first I thought it was a blocking issue due to using async methods inside API and inside the resource store implementation. After removing all async coding to determine if that was the problem I now find in my log files the error message in the title of this issue. I am using IdentityServerTools to get access token for accessing the API. I had no trouble with implementing IClientStore and IUserProfile interfaces using calls to API. I one thing I have found in debugging this over the past couple days is the the IResourceStore implementation gets hammered during introspection in this scenario - sounds like some caching is needed. Using IdSrv4 2.3.0 and ASP.NET Core 2.1.300 Full error message and code location: InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]' Microsoft.IdentityModel.Protocols.ConfigurationManager<>.GetConfigurationAsync(CancellationToken cancel) in "C:\agent2_work\15\s\src\Microsoft.IdentityModel.Protocols\Configuration\ConfigurationManager.cs", line 211
Same here. I was working through the quickstarts sections, was about to test the MVC Client and I got the same error.
InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]'.
Microsoft.IdentityModel.Protocols.ConfigurationManager<T>.GetConfigurationAsync(CancellationToken cancel)
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleChallengeAsync(AuthenticationProperties properties)
Microsoft.AspNetCore.Authentication.AuthenticationHandler<TOptions>.ChallengeAsync(AuthenticationProperties properties)
Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, string scheme, AuthenticationProperties properties)
Microsoft.AspNetCore.Mvc.ChallengeResult.ExecuteResultAsync(ActionContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAlwaysRunResultFilters()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
I've got this exact issue running in Docker in Azure too (Azure App Services - Linux Containers).
I've disabled the PII masking, so I can see exactly what the URL. What's interesting here is that the URL it says it's 'Unable to object configuration from', when copied into a browser, works just fine.
It's a routing issue. Otherwise, the other likely culprit is an https requirement.
I've just noticed, when running in Docker the responses from the .well-known/openid-configuration endpoint are all http, but the entire app is setup to be https.
I've no idea how to turn that on.
Are you setting the Authority as raw domain without https? then that's the issue, change it and it's going to work.
Not sure why but this was the issue for me.
Same as @forlayo here. In the Startup.cs of my ASP.NET Core 2.1 client application I was configured to use HTTP to reach the authority but in the Debug properties of my IdentityServer project I was set to use HTTPS. Updating the authority to HTTPS resolved the issue.
In my case, I was debugging in my local computer and needed to open the local Port, e.g., 5100-5105 to the IdentityServer. Then it worked well!
Am having the same issue here trying to debug on my local, is there any solution to this yet? @tparikka the scheme on mine is already on HTTPS yet it's not working
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.ConfigurationManager1.GetConfigurationAsync(CancellationToken cancel) at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync() at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
@victorud In the project settings for my STS I was set to host on HTTPS, but in Startup.cs of the client application my Authority was set to http://localhost:5050 instead of https://localhost:5050. It's part of the ConfigureServices method:
services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
options.Authority = "https://localhost:50500";
options.RequireHttpsMetadata = false;
options.ApiName = "api1";
});
Use the login.microsoftonline.com for the instance in appsettings.json
"Instance" : "https://login.microsoftonline.com/"
Am having the same issue here trying to debug on my local, is there any solution to this yet? @tparikka the scheme on mine is already on HTTPS yet it's not working
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.ConfigurationManager1.GetConfigurationAsync(CancellationToken cancel) at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync() at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
I later realised it has to do with the route. The issue has been resolved