Zum Inhalt springen
ecdsa.com
Microsoft.IdentityModel.Protocols (.NET).NET

Fehlermeldung

IDX20803: Unable to obtain configuration from: 'http://keycloak:8080/realms/main/.well-known/openid-configuration'.

Auch ausgegeben als

  • System.InvalidOperationException: IDX20803: Unable to obtain configuration from:
  • IDX20108: The address specified 'http://keycloak:8080/realms/main/.well-known/openid-configuration' is not valid as per HTTPS scheme. Please specify an https address for security reasons.
  • IDX20804: Unable to retrieve document from:

Die Meldung geht mit „Will retry at '…'. Exception: '…'“ und dem Text der inneren Exception weiter. Die URL ist deine `Authority` + `/.well-known/openid-configuration` oder deine `MetadataAddress`.

Microsoft.IdentityModel.Protocols (.NET) — ConfigurationManager<OpenIdConnectConfiguration>, used by JwtBearer and OpenIdConnect handlers

Was der Fehler bedeutet

Der Konfigurationsmanager konnte das Discovery-Dokument von OpenID Connect nicht herunterladen (oder nicht parsen), deshalb hat der Handler für JWT Bearer oder OpenID Connect keinen Aussteller und keine Signaturschlüssel. Dann wird jedes Token abgelehnt, typischerweise gefolgt von den Fehlern IDX10500/IDX10503. Der eigentliche Grund steht in der inneren Exception: IDX20108, wenn die Metadatenadresse reines HTTP verwendet, aber HTTPS verlangt ist, sonst IDX20804 mit einem Netzwerk- oder TLS-Fehler.

Warum der Fehler auftritt

So behebst du den Fehler

  1. 1.

    HTTP-Metadaten nur in der Entwicklung zulassen

    Binde `RequireHttpsMetadata = false` an die Entwicklungsumgebung; in Produktion muss die Authority HTTPS verwenden, weil die heruntergeladenen Schlüssel darüber entscheiden, welche Tokens du akzeptierst.

    csharp
    builder.Services.AddAuthentication().AddJwtBearer(options =>
    {
        options.Authority = builder.Configuration["Auth:Authority"];
        // Plain HTTP only for local development containers; production authorities must be HTTPS.
        options.RequireHttpsMetadata = !builder.Environment.IsDevelopment();
    });
  2. 2.

    URL von dort abrufen, wo die API läuft

    Führe die Anfrage im Container oder Pod der API aus. Eine Antwort mit Status 200 und JSON bestätigt Netzwerk und TLS; alles andere zeigt dir, auf welcher Ebene du das Problem beheben musst.

    bash
    # From inside the API container: DNS, TLS and HTTP status of the metadata URL
    curl -sS -o /dev/null -w '%{http_code} %{ssl_verify_result}\n' https://login.example.com/realms/main/.well-known/openid-configuration

Verwandte Fehler

Gesamte Signaturfehler-Datenbank durchsuchen