Skip to content

Dynamic Client Registration

OAuth 2.0 Dynamic Client Registration (RFC 7591) and Client Registration Management (RFC 7592): register a client at runtime, then read, update, and deregister it through the management URI the registration response returns.

Like the other endpoint clients, these functions return an error-carrying response instead of raising on protocol errors — check is_successful before touching the guarded fields (client_id, client_secret, registration_access_token, registration_client_uri). Secrets are redacted from repr().

from py_identity_model import (
    ClientDeleteRequest,
    ClientReadRequest,
    ClientRegistrationRequest,
    ClientUpdateRequest,
    delete_client,
    read_client,
    register_client,
    update_client,
)

registered = register_client(
    ClientRegistrationRequest(
        address=disco.registration_endpoint,
        redirect_uris=["https://rp.example.com/callback"],
        client_name="my-app",
        token_endpoint_auth_method="client_secret_basic",
        initial_access_token=initial_access_token,  # if the endpoint is protected
    )
)
mgmt_uri = registered.registration_client_uri
token = registered.registration_access_token

read = read_client(ClientReadRequest(address=mgmt_uri, registration_access_token=token))
token = read.registration_access_token or token  # RFC 7592 §3: the OP MAY rotate it

updated = update_client(
    ClientUpdateRequest(
        address=mgmt_uri,
        registration_access_token=token,
        client_id=registered.client_id,          # the PUT body must carry client_id
        redirect_uris=["https://rp.example.com/callback"],
        client_name="my-app-renamed",
        client_secret=registered.client_secret,  # echo back when required
    )
)
token = updated.registration_access_token or token

delete_client(ClientDeleteRequest(address=mgmt_uri, registration_access_token=token))

Two RFC 7592 behaviors to keep in mind: an update sends the full client metadata (fields omitted from ClientUpdateRequest are treated by the server as removed), and the OP may rotate registration_access_token on every management response — always use the freshest token returned.

Models

ClientRegistrationRequest(address, redirect_uris, response_types=None, grant_types=None, application_type=None, contacts=None, client_name=None, logo_uri=None, client_uri=None, policy_uri=None, tos_uri=None, token_endpoint_auth_method=None, scope=None, jwks_uri=None, extra_metadata=None, initial_access_token=None) dataclass

Bases: BaseRequest

Request to register a client (RFC 7591 Section 3, OIDC Registration 1.0).

The optional response_types, grant_types, application_type, contacts, client_name, logo_uri, client_uri, policy_uri, tos_uri, token_endpoint_auth_method, scope, and jwks_uri fields carry the client metadata of RFC 7591 Section 2.

Attributes:

Name Type Description
address str

The client registration endpoint URL.

redirect_uris list[str]

Redirection URIs registered for the client.

extra_metadata dict | None

Additional metadata merged into the request body (e.g. sector_identifier_uri, subject_type) so OIDC-specific fields flow without a dedicated attribute.

initial_access_token str | None

Optional bearer token for a protected registration endpoint (RFC 7591 Section 3).

ClientReadRequest(address, registration_access_token) dataclass

Bases: BaseRequest

Request to read a client configuration (RFC 7592 Section 2.1).

Attributes:

Name Type Description
address str

The client's registration_client_uri.

registration_access_token str

Bearer token issued at registration.

ClientUpdateRequest(address, registration_access_token, client_id, redirect_uris, response_types=None, grant_types=None, application_type=None, contacts=None, client_name=None, logo_uri=None, client_uri=None, policy_uri=None, tos_uri=None, token_endpoint_auth_method=None, scope=None, jwks_uri=None, client_secret=None, extra_metadata=None) dataclass

Bases: BaseRequest

Request to update a client configuration (RFC 7592 Section 2.2).

The PUT body MUST include client_id and the full client metadata; omitted fields are treated by the server as removed.

Attributes:

Name Type Description
address str

The client's registration_client_uri.

registration_access_token str

Bearer token issued at registration.

client_id str

The registered client identifier (required in the body).

redirect_uris list[str]

Full redirect URI list to persist.

client_secret str | None

Current client secret, echoed back when required.

extra_metadata dict | None

Additional metadata merged into the request body.

ClientDeleteRequest(address, registration_access_token) dataclass

Bases: BaseRequest

Request to deregister a client (RFC 7592 Section 2.3).

Attributes:

Name Type Description
address str

The client's registration_client_uri.

registration_access_token str

Bearer token issued at registration.

ClientRegistrationResponse(is_successful, error=None, client_id=None, client_secret=None, client_id_issued_at=None, client_secret_expires_at=None, registration_access_token=None, registration_client_uri=None, metadata=None) dataclass

Bases: BaseResponse

Response from the client registration endpoint (RFC 7591 / RFC 7592).

Returned by register, read, and update operations. Check is_successful before accessing client_id, client_secret, registration_access_token or registration_client_uri. metadata echoes the full client configuration returned by the server.

ClientDeleteResponse(is_successful, error=None) dataclass

Bases: BaseResponse

Response from deregistering a client (RFC 7592 Section 2.3).

A successful deletion returns is_successful=True with no data fields (the server responds with 204 No Content).

Sync API

register_client(request, http_client=None)

Register a client at the registration endpoint (RFC 7591 Section 3).

Parameters:

Name Type Description Default
request ClientRegistrationRequest

Registration request with client metadata.

required
http_client HTTPClient | None

Optional managed HTTP client.

None

Returns:

Type Description
ClientRegistrationResponse

ClientRegistrationResponse with the issued client_id and, for

ClientRegistrationResponse

protected clients, registration_access_token /

ClientRegistrationResponse

registration_client_uri for subsequent management (RFC 7592).

read_client(request, http_client=None)

Read a client's current configuration (RFC 7592 Section 2.1).

Parameters:

Name Type Description Default
request ClientReadRequest

Read request targeting registration_client_uri.

required
http_client HTTPClient | None

Optional managed HTTP client.

None

Returns:

Type Description
ClientRegistrationResponse

ClientRegistrationResponse with the current client metadata.

update_client(request, http_client=None)

Update a client's configuration (RFC 7592 Section 2.2).

Parameters:

Name Type Description Default
request ClientUpdateRequest

Update request with the full client metadata (including client_id).

required
http_client HTTPClient | None

Optional managed HTTP client.

None

Returns:

Type Description
ClientRegistrationResponse

ClientRegistrationResponse with the persisted client metadata.

delete_client(request, http_client=None)

Deregister a client (RFC 7592 Section 2.3).

Parameters:

Name Type Description Default
request ClientDeleteRequest

Delete request targeting registration_client_uri.

required
http_client HTTPClient | None

Optional managed HTTP client.

None

Returns:

Type Description
ClientDeleteResponse

ClientDeleteResponse; is_successful is True for a 204 response.

Async API

register_client(request, http_client=None) async

Register a client at the registration endpoint (RFC 7591 Section 3, async).

Parameters:

Name Type Description Default
request ClientRegistrationRequest

Registration request with client metadata.

required
http_client AsyncHTTPClient | None

Optional managed HTTP client.

None

Returns:

Type Description
ClientRegistrationResponse

ClientRegistrationResponse with the issued client_id and, for

ClientRegistrationResponse

protected clients, registration_access_token /

ClientRegistrationResponse

registration_client_uri for subsequent management (RFC 7592).

read_client(request, http_client=None) async

Read a client's current configuration (RFC 7592 Section 2.1, async).

Parameters:

Name Type Description Default
request ClientReadRequest

Read request targeting registration_client_uri.

required
http_client AsyncHTTPClient | None

Optional managed HTTP client.

None

Returns:

Type Description
ClientRegistrationResponse

ClientRegistrationResponse with the current client metadata.

update_client(request, http_client=None) async

Update a client's configuration (RFC 7592 Section 2.2, async).

Parameters:

Name Type Description Default
request ClientUpdateRequest

Update request with the full client metadata (including client_id).

required
http_client AsyncHTTPClient | None

Optional managed HTTP client.

None

Returns:

Type Description
ClientRegistrationResponse

ClientRegistrationResponse with the persisted client metadata.

delete_client(request, http_client=None) async

Deregister a client (RFC 7592 Section 2.3, async).

Parameters:

Name Type Description Default
request ClientDeleteRequest

Delete request targeting registration_client_uri.

required
http_client AsyncHTTPClient | None

Optional managed HTTP client.

None

Returns:

Type Description
ClientDeleteResponse

ClientDeleteResponse; is_successful is True for a 204 response.