Skip to content

Discovery

OpenID Connect Discovery 1.0 document fetching and parsing.

Request / Response Models

DiscoveryDocumentRequest(address, policy=None) dataclass

Bases: BaseRequest

Request for fetching an OpenID Connect discovery document.

Attributes:

Name Type Description
address str

The base URL of the identity provider (e.g. https://example.com). The well-known path is appended automatically.

policy DiscoveryPolicy | None

Optional discovery policy for configuring validation behavior. When None, strict defaults apply.

DiscoveryDocumentResponse(is_successful, error=None, issuer=None, jwks_uri=None, authorization_endpoint=None, token_endpoint=None, response_types_supported=None, subject_types_supported=None, id_token_signing_alg_values_supported=None, userinfo_endpoint=None, registration_endpoint=None, introspection_endpoint=None, scopes_supported=None, response_modes_supported=None, grant_types_supported=None, acr_values_supported=None, id_token_encryption_alg_values_supported=None, id_token_encryption_enc_values_supported=None, userinfo_signing_alg_values_supported=None, userinfo_encryption_alg_values_supported=None, userinfo_encryption_enc_values_supported=None, request_object_signing_alg_values_supported=None, request_object_encryption_alg_values_supported=None, request_object_encryption_enc_values_supported=None, token_endpoint_auth_methods_supported=None, token_endpoint_auth_signing_alg_values_supported=None, display_values_supported=None, claim_types_supported=None, claims_supported=None, claims_locales_supported=None, ui_locales_supported=None, code_challenge_methods_supported=None, pushed_authorization_request_endpoint=None, require_pushed_authorization_requests=None, claims_parameter_supported=None, request_parameter_supported=None, request_uri_parameter_supported=None, require_request_uri_registration=None, authorization_response_iss_parameter_supported=None, authorization_signing_alg_values_supported=None, authorization_encryption_alg_values_supported=None, authorization_encryption_enc_values_supported=None, mtls_endpoint_aliases=None, tls_client_certificate_bound_access_tokens=None, end_session_endpoint=None, backchannel_logout_supported=None, backchannel_logout_session_supported=None, service_documentation=None, op_policy_uri=None, op_tos_uri=None, cache_control=None, *, error_kind=None, status_code=None, missing_fields=()) dataclass

Bases: BaseResponse

Response from an OpenID Connect discovery document fetch.

Check is_successful before accessing data fields. Accessing guarded fields on a failed response raises FailedResponseAccessError.

Sync API

get_discovery_document(disco_doc_req, http_client=None)

Fetch discovery document from the specified address.

Parameters:

Name Type Description Default
disco_doc_req DiscoveryDocumentRequest

Discovery document request configuration

required
http_client HTTPClient | None

Optional managed HTTP client. When None, uses the thread-local default.

None

Returns:

Name Type Description
DiscoveryDocumentResponse DiscoveryDocumentResponse

Discovery document response

Async API

get_discovery_document(disco_doc_req, http_client=None) async

Fetch discovery document from the specified address (async).

Parameters:

Name Type Description Default
disco_doc_req DiscoveryDocumentRequest

Discovery document request configuration

required
http_client AsyncHTTPClient | None

Optional managed HTTP client. When None, uses the module-level singleton.

None

Returns:

Name Type Description
DiscoveryDocumentResponse DiscoveryDocumentResponse

Discovery document response

Failure diagnostics

Sync and async discovery return the same structured diagnostics on a failed DiscoveryDocumentResponse. error remains human-readable text; use error_kind for classification instead of parsing that text.

from py_identity_model import DiscoveryErrorKind

if response.error_kind is DiscoveryErrorKind.UNEXPECTED_STATUS:
    retry_later(response.status_code)
DiscoveryErrorKind Meaning Additional details
UNEXPECTED_STATUS The endpoint returned a non-success HTTP status status_code is the actual HTTP status
INVALID_JSON The response body could not be decoded as JSON
MISSING_FIELDS A required-field check failed missing_fields lists the fields rejected by that check
HTTPS_REQUIRED A URL violated the policy's HTTPS requirement
INVALID_CONFIGURATION Another URL or configuration check failed
INVALID_DOCUMENT Another discovery document check failed
NETWORK_ERROR The HTTP transport failed
UNEXPECTED_ERROR An unclassified exception occurred

On success, error_kind and status_code are None, and missing_fields is empty. These fields are optional keyword-only additions; existing positional response constructors and exception base classes remain compatible.

The metadata describes the checks the library actually performs. It does not add issuer matching (#574) or make the authorization/token endpoints required (#771). A field failure reports the fields in the failing check, rather than claiming an exhaustive audit of the whole document.