ASP.NET Core JwtBearer throws IDX20803: Unable to obtain configuration from the metadata address
IDX20803: Unable to obtain configuration from: 'https://login.microsoftonline.com/<tenant>/v2.0/.well-known/openid-configuration'.Short answer
IDX20803 means the API could not download the OpenID Connect discovery document from Authority or MetadataAddress, so it has no signing keys. Fetch that URL from the same server with curl. The usual causes are a wrong authority or tenant, an http:// address while RequireHttpsMetadata is true, or a network path that blocks the request.
Fix it fast
1Find out which cause you have
Take the URL from the exception message and request it from the server that runs the API, not from your laptop.
curl -i https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration2Match what you see, then jump to its fix
- 1
curl on the URL in the exception returns 404 or an HTML page, not JSONAuthority or MetadataAddress points to a document that does not existFix - 2
The authority is http://, for example a local identity server or a container name; curl works but the API still failsThe authority is plain http while RequireHttpsMetadata is trueFix - 3
curl from the server hangs, times out or fails on DNS or TLS, while it works from your laptopThe API host cannot reach the identity providerFix
- 1
What does the error look like?
IDX20803: Unable to obtain configuration from: 'https://login.microsoftonline.com/<tenant>/v2.0/.well-known/openid-configuration'.
Cause 1 of 3
Authority or MetadataAddress points to a document that does not exist
1Check
The configuration document is the authority URL plus /.well-known/openid-configuration. For Entra ID the authority is https://login.microsoftonline.com/{tenant}/v2.0, and {tenant} is common, organizations, consumers, a tenant ID or a verified domain. A typo, a placeholder left in appsettings, or an authority that already ends in the well-known path breaks it.
dotnet user-secrets list 2>/dev/null | grep -i authority
grep -n "Authority\|MetadataAddress\|Instance\|TenantId" appsettings*.json2Fix
Set Authority to the issuer base only. JwtBearer adds the well-known path itself.
builder.Services.AddAuthentication("Bearer").AddJwtBearer(o =>
{
o.Authority = "https://login.microsoftonline.com/<tenant-id>/v2.0";
o.Audience = "api://<application-id>";
});3Verify
curl on Authority plus /.well-known/openid-configuration returns JSON with jwks_uri, and the API accepts a valid token.
curl -s https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration | head -c 300Confirmed by learn.microsoft.com
Cause 2 of 3
The authority is plain http while RequireHttpsMetadata is true
1Check
RequireHttpsMetadata defaults to true, which refuses an http:// metadata address. This is a development switch only.
grep -n 'RequireHttpsMetadata\|Authority' Program.cs appsettings*.json2Fix
Use an https:// authority. For a local identity server in Development only, turn the check off.
builder.Services.AddAuthentication("Bearer").AddJwtBearer(o =>
{
o.Authority = builder.Configuration["Auth:Authority"];
o.RequireHttpsMetadata = !builder.Environment.IsDevelopment();
});3Verify
Start the API and call a protected endpoint with a valid token.
curl -i -H "Authorization: Bearer $TOKEN" https://localhost:5001/api/meConfirmed by learn.microsoft.com
Cause 3 of 3
The API host cannot reach the identity provider
1Check
The metadata is fetched by the API process through its backchannel HTTP client. Egress firewalls, a corporate proxy, a container without DNS or an untrusted TLS certificate stop it.
curl -v --max-time 10 https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration
getent hosts login.microsoftonline.com2Fix
Open outbound HTTPS to the identity provider, set the proxy for the process, or give JwtBearer a backchannel handler that uses your proxy. Raise BackchannelTimeout only if the link is slow.
builder.Services.AddAuthentication("Bearer").AddJwtBearer(o =>
{
o.Authority = builder.Configuration["Auth:Authority"];
o.BackchannelTimeout = TimeSpan.FromSeconds(30);
// o.BackchannelHttpHandler = new HttpClientHandler { Proxy = new WebProxy("http://proxy.internal:3128") };
});3Verify
curl from the server returns the JSON document, and the first protected call no longer throws.
curl -s --max-time 10 https://login.microsoftonline.com/<tenant-id>/v2.0/.well-known/openid-configuration | head -c 200Confirmed by learn.microsoft.com
How do I stop it coming back?
- Keep Authority in configuration per environment and print it at start-up in a log line.
- Add a smoke test that fetches the discovery document from the deployed host.
- Allow outbound HTTPS to your identity provider when you write firewall or container rules.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Security
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fixSecurity
An [Authorize] endpoint rejects a request with a bearer token
Authorization Header sent: no Bearer token sent.
An [Authorize] endpoint without a policy name requires an authenticated user.
4 causes, each with a fixSecurity
ASP.NET Core API rejects an Angular user's token: the signature key was not found
401 Unauthorized
The API looked for the key named by the token's kid in the key set it downloaded from your Authority, and the key was not there.
4 causes, each with a fixSecurity
ASP.NET Core rejects the token before checking it: IDX12741, three segments expected
401 Unauthorized
IDX12741 means the string the API pulled out of the Authorization header is not shaped like a JWT: a signed token has three dot-separated parts and an encrypted one has five.
3 causes, each with a fixSecurity
A Microsoft Entra access token shows Invalid Signature when you check it yourself
Tokens that a Microsoft API receives might not always be a JWT that can be decoded
A token issued for Microsoft Graph is not meant for you to validate, so a failed signature check is expected.
2 causes, each with a fix