Dynamic client registration

This documentation was generated with the assistance of AI. Please report any inaccuracies.

OpenID Connect Dynamic Client Registration lets a piece of software register itself as a client by posting its metadata to the server, instead of an administrator creating it. auth-server offers Spring Authorization Server’s registration endpoint, /connect/register, but only when authserver.oidc.client-registration.enabled=true; it is off by default. Even then registration is not open: the caller must present an initial access token with the scope client.create, obtained by a client that an administrator created with that scope, and each initial token can be used once. The normal way to manage clients in this repository is the administration API (/api/admin/clients, see Registered clients), which validates every client against the domain model and supports the repository’s own settings; dynamic registration bypasses both.

At a glance

Item Value

Actors

An administrator (once), the registering software (holding the client that may create clients), auth-server.

Clients

A confidential client with the grant client_credentials and the scope client.create, created through POST /api/admin/clients; the new client created by the registration.

Preconditions

authserver.oidc.client-registration.enabled=true (default false in application.yml). Then DynamicClientRegistrationConfiguration (@ConditionalOnProperty) declares a ProtocolChainCustomizer that turns on clientRegistrationEndpoint of the OIDC configurer. No profile is involved.

Endpoints

POST /oauth2/token (grant_type=client_credentials&scope=client.create), POST /connect/register (register), GET /connect/register?client_id=…​ (read the registration with the registration access token, scope client.read). The discovery document advertises registration_endpoint only while the property is on.

The whole wiring:

    /**
     * Creates the customizer that turns on the client registration endpoint of the protocol chain.
     *
     * @return the customizer.
     */
    @Bean
    public ProtocolChainCustomizer clientRegistrationProtocolChainCustomizer() {
        return server -> server.oidc(oidc -> oidc.clientRegistrationEndpoint(Customizer.withDefaults()));
    }

Steps

  1. An administrator creates a client with POST /api/admin/clients: confidential, grant client_credentials, scope client.create. Its generated secret is shown once in the creation response.

  2. The registering software obtains an initial access token: POST /oauth2/token with grant_type=client_credentials&scope=client.create, authenticating with that client.

  3. It posts its metadata as JSON to /connect/register with Authorization: Bearer <initial token>: for example client_name, redirect_uris, grant_types, token_endpoint_auth_method, optionally post_logout_redirect_uris and jwks_uri.

  4. Without a bearer token the request never reaches the endpoint: the protocol chain’s entry point redirects to /login.

  5. OidcClientRegistrationAuthenticationProvider finds the authorization of the initial token, requires it to be active and to carry client.create, and validates the metadata with the framework’s default validator: redirect and post-logout redirect URIs must have a safe scheme and no fragment, the jwks_uri is checked, and any scope in the request is refused (invalid_scope). It also checks that a signing algorithm is only given for the JWT authentication methods.

  6. The framework converts the metadata into a RegisteredClient (generated client_id, a generated secret for the client_secret_* methods, grant authorization_code when none is given, PKCE required and consent required), encodes the secret with the application’s PasswordEncoder and saves it through the RegisteredClientRepository bean (JdbcRegisteredClientRepository, table oauth2_registered_client).

  7. It issues a registration access token (scope client.read) for the new client and invalidates the initial access token, which cannot register a second client.

  8. The answer is 201 Created with the client metadata, client_id, client_secret (shown only here), registration_access_token and registration_client_uri.

  9. Later the software may read its registration with GET /connect/register?client_id=…​ and the registration access token.

sequenceDiagram autonumber participant Ad as Administrator participant S as Registering software participant A as auth-server Ad->>A: POST /api/admin/clients with grant client_credentials and scope client.create A-->>Ad: 201 with client_id and secret, shown once S->>A: POST /oauth2/token grant_type=client_credentials scope=client.create A-->>S: initial access token S->>A: POST /connect/register with Bearer initial token and client metadata Note over A: token active with client.create, metadata validated A->>A: save RegisteredClient, encode secret Note over A: initial token invalidated A-->>S: 201 client_id, client_secret, registration_access_token, registration_client_uri S->>A: GET /connect/register?client_id=... with Bearer registration token A-->>S: 200 client metadata
flowchart TD Start(["POST /connect/register"]) --> Enabled{"client-registration.enabled?"} Enabled -- "no" --> NotThere["No registration endpoint on the protocol chain"] Enabled -- "yes" --> Bearer{"Bearer token sent?"} Bearer -- "no" --> Login["302 to /login"] Bearer -- "yes" --> Active{"Token active and has client.create?"} Active -- "no" --> Refused["Error: invalid_token or insufficient_scope"] Active -- "yes" --> Valid{"Metadata valid and no scope requested?"} Valid -- "no" --> Meta["400 invalid_redirect_uri, invalid_scope or invalid_client_metadata"] Valid -- "yes" --> Created["201 client created, initial token invalidated"]

Tokens and claims

The registration response carries the registration_access_token, a bearer token with the scope client.read for that client only. The new client’s own tokens later come from the usual grants, with one consequence of skipping the admin API: the registered client has none of the repository’s custom settings, in particular no settings.client.audiences, so IssuedTokenClaims leaves the framework’s default aud, the client id. Its access tokens therefore are not accepted by the resource server (audience resource-server) or by the /api/** chain (audience auth-server) until an administrator sets audiences on it with PUT /api/admin/clients/{clientId}. And because scopes are refused at registration, the client starts with no scopes.

Dynamic registration and the administration API

Aspect Dynamic registration (/connect/register) Administration API (/api/admin/clients)

Availability

Off unless authserver.oidc.client-registration.enabled=true

Always on

Who may call

A bearer token with scope client.create, used once

A bearer token for the API audience (auth-server) with scope admin

Validation

Spring Authorization Server’s defaults (redirect URIs, jwks_uri, no scopes, auth method and algorithm)

The domain ClientRegistration rules: a public client requires PKCE, tls_client_auth needs a subject DN, private_key_jwt needs keys, implicit refused, private JWK material refused, and more

Settings

Standard client metadata only

Also audiences, requireConsent, mfaRequired, token lifetimes and format, reuseRefreshTokens, postLogoutRedirectUris, client authentication settings

Operations

Register and read

List, read, create, update, delete (with its authorizations and consents), rotate secret

Contract

Framework-owned endpoint, exempt from the OpenAPI contracts

Defined in apis/auth-server/rest-server/auth-server-api-v1.yaml, implemented by ClientAdminController

Both write the same oauth2_registered_client table through the same RegisteredClientRepository.

How it is tested

  • auth-server/boot ClientAdminIT (which enables the property for its context): dynamicRegistration_whenEnabledAndTokenHasTheScope_registersAClientWithAnEncodedSecret registers a client with an initial token from a client_credentials client with client.create and checks that the stored secret is encoded; dynamicRegistration_whenThereIsNoToken_isRejected checks the redirect without a token.

  • auth-server/api/web DynamicClientRegistrationConfigurationTest: the customizer turns on the endpoint.