エラーメッセージ
IDX20803: Unable to obtain configuration from: 'http://keycloak:8080/realms/main/.well-known/openid-configuration'.
別の表記
- 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:
メッセージは「Will retry at '…'. Exception: '…'」と内部例外のテキストへと続きます。URL は、設定した `Authority` + `/.well-known/openid-configuration`、または `MetadataAddress` です。
Microsoft.IdentityModel.Protocols (.NET) — ConfigurationManager<OpenIdConnectConfiguration>, used by JwtBearer and OpenIdConnect handlers
このエラーの意味
構成マネージャーが OpenID Connect のディスカバリドキュメントをダウンロード(または解析)できなかったため、JWT Bearer ハンドラーや OpenID Connect ハンドラーには発行者も署名鍵もありません。その結果、すべてのトークンが拒否され、通常は IDX10500/IDX10503 エラーが続きます。本当の原因は内部例外にあります。HTTPS が必須なのにメタデータアドレスが平文 HTTP の場合は IDX20108、それ以外の場合はネットワークまたは TLS のエラーを伴う IDX20804 です。
発生する理由
RequireHttpsMetadata が有効なのにメタデータアドレスが HTTP
よくあるローカルの Keycloak や IdentityServer のコンテナーには、`http://service:8080` で接続することがよくあります。`RequireHttpsMetadata` はデフォルトで true なので、メタデータの取得処理は接続する前にこのアドレスを拒否します(IDX20108)。
API から Authority に到達できない
よくあるクラスターの外でしか名前解決できない DNS、ファイアウォールや送信用プロキシ、または `localhost` がコンテナー自身を指すコンテナーネットワークが原因です。
TLS 証明書が信頼されていない
ときどきID プロバイダーが自己署名証明書や社内 CA の証明書を使っている場合、その CA を API のコンテナー内にインストールしない限り、コンテナー内からの HTTPS リクエストは失敗します。
Authority のパスが間違っている
ときどき`/realms/<name>`(Keycloak)、テナント ID、`/v2.0`(Entra ID)が欠けていると、ディスカバリ URL が 404 を返します。
修正方法
- 1.
HTTP のメタデータは開発環境でのみ許可する
`RequireHttpsMetadata = false` は開発環境に限定してください。本番環境では Authority は HTTPS でなければなりません。ダウンロードした鍵によって、どのトークンを受け入れるかが決まるからです。
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.
API が動作している場所から URL を取得する
API のコンテナーまたは Pod の中からリクエストを実行してください。JSON 付きの 200 が返ればネットワークと TLS に問題はありません。それ以外の応答なら、修正すべきレイヤーが分かります。
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
関連するエラー
IDX10503: Signature validation failed. The token's kid is: '2026-10', but did n…Microsoft.IdentityModel.JsonWebTokens / System.IdentityModel.Tokens.Jwt (.NET)Expected 200 OK from the JSON Web Key Set HTTP responsejose (JavaScript)oidc: issuer URL provided to client ("https://accounts.example.com") did not ma…coreos/go-oidc (Go)