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), |
Clients |
A confidential client with the grant |
Preconditions |
|
Endpoints |
|
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
-
An administrator creates a client with
POST /api/admin/clients: confidential, grantclient_credentials, scopeclient.create. Its generated secret is shown once in the creation response. -
The registering software obtains an initial access token:
POST /oauth2/tokenwithgrant_type=client_credentials&scope=client.create, authenticating with that client. -
It posts its metadata as JSON to
/connect/registerwithAuthorization: Bearer <initial token>: for exampleclient_name,redirect_uris,grant_types,token_endpoint_auth_method, optionallypost_logout_redirect_urisandjwks_uri. -
Without a bearer token the request never reaches the endpoint: the protocol chain’s entry point redirects to
/login. -
OidcClientRegistrationAuthenticationProviderfinds the authorization of the initial token, requires it to be active and to carryclient.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, thejwks_uriis checked, and anyscopein the request is refused (invalid_scope). It also checks that a signing algorithm is only given for the JWT authentication methods. -
The framework converts the metadata into a
RegisteredClient(generatedclient_id, a generated secret for theclient_secret_*methods, grantauthorization_codewhen none is given, PKCE required and consent required), encodes the secret with the application’sPasswordEncoderand saves it through theRegisteredClientRepositorybean (JdbcRegisteredClientRepository, tableoauth2_registered_client). -
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. -
The answer is
201 Createdwith the client metadata,client_id,client_secret(shown only here),registration_access_tokenandregistration_client_uri. -
Later the software may read its registration with
GET /connect/register?client_id=…and the registration access token.
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 |
Always on |
Who may call |
A bearer token with scope |
A bearer token for the API audience ( |
Validation |
Spring Authorization Server’s defaults (redirect URIs, |
The domain |
Settings |
Standard client metadata only |
Also |
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 |
Both write the same oauth2_registered_client table through the same RegisteredClientRepository.
How it is tested
-
auth-server/bootClientAdminIT(which enables the property for its context):dynamicRegistration_whenEnabledAndTokenHasTheScope_registersAClientWithAnEncodedSecretregisters a client with an initial token from aclient_credentialsclient withclient.createand checks that the stored secret is encoded;dynamicRegistration_whenThereIsNoToken_isRejectedchecks the redirect without a token. -
auth-server/api/webDynamicClientRegistrationConfigurationTest: the customizer turns on the endpoint.