Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

ASP.NET Core JwtBearer throws IDX20803: Unable to obtain configuration from the metadata address

ErrorIDX20803: 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.

  • Applies to ASP.NET Core 8, 9 and 10 with Microsoft.AspNetCore.Authentication.JwtBearer, Microsoft Entra ID v2.0 endpoint
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-configuration
  2. 2Match what you see, then jump to its fix

    1. 1curl 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. 2The 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. 3curl 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

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*.json

2Fix

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 300

Confirmed by learn.microsoft.com

Did this fix it?

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*.json

2Fix

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/me

Confirmed by learn.microsoft.com

Did this fix it?

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.com

2Fix

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 200

Confirmed by learn.microsoft.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.