Registered clients

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

Default clients and seeding

DefaultClientDefinitions (module application) is the single definition of the confidential bff client and the public spa-public client. Both carry the audiences resource-server and the authorization server’s own API (authserver.api.audience, default auth-server, so their users can change their password), the scopes openid, profile, documents.read and documents.delete, and never admin. Nothing environment-specific lives in the definitions: the redirect URIs come from configuration.

The idempotent ClientSeeder seeds, at start, only the clients whose redirect URIs are configured (authserver.clients.bff.redirect-uris / AUTHSERVER_BFF_REDIRECT_URIS and authserver.clients.spa-public.redirect-uris / AUTHSERVER_SPA_REDIRECT_URIS, comma-separated). Nothing is configured by default, so a deployment never gets a client, or a localhost redirect URI, it did not ask for; the dev profile (application-dev.yml) sets the local ones. The bff secret comes from the environment variable AUTHSERVER_BFF_CLIENT_SECRET (authserver.clients.bff-secret); when it is empty the confidential client is not seeded. Secrets are stored encoded and never committed. The dev profile data initializer uses the same definition and the configured redirect URIs with a generated secret that it logs.

  clients:
    # Secret of the confidential bff client, from the environment only; empty means the client is not seeded.
    bff-secret: ${AUTHSERVER_BFF_CLIENT_SECRET:}
    # Redirect URIs (comma-separated) of the default clients. A client is seeded only when its redirect URIs are
    # configured: nothing is seeded by default, and no localhost URI exists outside the dev profile.
    bff:
      redirect-uris: ${AUTHSERVER_BFF_REDIRECT_URIS:}
      # URIs (comma-separated) the user may be sent to after an RP-initiated logout (/connect/logout); none by default
      post-logout-redirect-uris: ${AUTHSERVER_BFF_POST_LOGOUT_REDIRECT_URIS:}
    spa-public:
      redirect-uris: ${AUTHSERVER_SPA_REDIRECT_URIS:}
      post-logout-redirect-uris: ${AUTHSERVER_SPA_POST_LOGOUT_REDIRECT_URIS:}
    /**
     * Defines the {@code bff} client: confidential, {@code client_secret_basic}, authorization code with PKCE and
     * refresh tokens, with refresh token rotation on. It requires the end-user's consent to the requested scopes.
     *
     * @param redirectUris redirect URIs of the deployment.
     * @param apiAudience  audience of the authorization server's own API.
     * @return the client.
     */
    public static ClientRegistration bff(final List<String> redirectUris, final String apiAudience) {
        return bff(redirectUris, apiAudience, List.of());
    }

    /**
     * Defines the {@code bff} client with the URIs it may be sent to after an OpenID Connect RP-initiated logout.
     *
     * @param redirectUris           redirect URIs of the deployment.
     * @param apiAudience            audience of the authorization server's own API.
     * @param postLogoutRedirectUris post-logout redirect URIs of the deployment; none when empty.
     * @return the client.
     */
    public static ClientRegistration bff(final List<String> redirectUris, final String apiAudience,
                                         final List<String> postLogoutRedirectUris) {
        return new ClientRegistration(BFF_CLIENT_ID, "Backend for Frontend", true,
                List.of("client_secret_basic"), List.of("authorization_code", "refresh_token"),
                redirectUris, SCOPES, true, List.of(RESOURCE_SERVER_AUDIENCE, apiAudience), ACCESS_TOKEN_TTL,
                REFRESH_TOKEN_TTL, ClientRegistration.FORMAT_SELF_CONTAINED, false,
                postLogoutRedirectUris, true, false, null, null, null, null, false);
    }

    /**
     * Defines the {@code spa-public} client: public, authorization code with PKCE, no client authentication.
     *
     * @param redirectUris redirect URIs of the deployment.
     * @param apiAudience  audience of the authorization server's own API.
     * @return the client.
     */
    public static ClientRegistration spaPublic(final List<String> redirectUris, final String apiAudience) {
        return spaPublic(redirectUris, apiAudience, List.of());
    }

    /**
     * Defines the {@code spa-public} client with the URIs it may be sent to after an OpenID Connect RP-initiated
     * logout.
     *
     * @param redirectUris           redirect URIs of the deployment.
     * @param apiAudience            audience of the authorization server's own API.
     * @param postLogoutRedirectUris post-logout redirect URIs of the deployment; none when empty.
     * @return the client.
     */
    public static ClientRegistration spaPublic(final List<String> redirectUris, final String apiAudience,
                                               final List<String> postLogoutRedirectUris) {
        return new ClientRegistration(SPA_PUBLIC_CLIENT_ID, "Single-page application", false,
                List.of("none"), List.of("authorization_code", "refresh_token"),
                redirectUris, SCOPES, true, List.of(RESOURCE_SERVER_AUDIENCE, apiAudience), ACCESS_TOKEN_TTL,
                REFRESH_TOKEN_TTL, ClientRegistration.FORMAT_SELF_CONTAINED, false,
                postLogoutRedirectUris, false, false, null, null, null, null, false);
    }

Each registration also carries postLogoutRedirectUris (where an RP-initiated logout may send the user, configured with authserver.clients.<client>.post-logout-redirect-uris) and requireConsent (the user must approve the scopes on the consent page; true for bff, false for spa-public). See Login pages and the BFF.

Token settings of each client (lifetimes, rotation, self-contained or reference access token format, audiences) are persisted with the registration.

                .tokenSettings(TokenSettings.builder()
                        .accessTokenTimeToLive(registration.accessTokenTtl())
                        .refreshTokenTimeToLive(registration.refreshTokenTtl())
                        .accessTokenFormat(new OAuth2TokenFormat(registration.accessTokenFormat()))
                        .reuseRefreshTokens(registration.reuseRefreshTokens())
                        .x509CertificateBoundAccessTokens(registration.certificateBoundAccessTokens())
                        .build());

Administration API

/api/admin/clients manages registered clients and needs a bearer token for the API audience with the scope admin (the ADMIN role alone does not suffice; see Tokens and signing keys).

Endpoint Behavior

GET /api/admin/clients, GET /api/admin/clients/{clientId}

Lists or reads clients. Secrets are never returned.

POST /api/admin/clients

Creates a client. A generated secret of a confidential client is shown once, in the creation response.

PUT /api/admin/clients/{clientId}

Updates a client; its secret is not changed.

DELETE /api/admin/clients/{clientId}

Deletes a client, with its authorizations (and so its tokens) and the consents granted to it, in one transaction.

POST /api/admin/clients/{clientId}/secret

Rotates the secret of a confidential client.

    /**
     * Registers a client.
     *
     * @param registration the client.
     * @return the stored client and, for a client that uses a secret, its generated secret;
     *         {@code null} when the client has no {@code client_secret_*} authentication method.
     * @throws ClientAlreadyExistsException if the client id is taken.
     * @throws ImplicitClientRefusedException if the client has the implicit grant type.
     */
    public CreatedClient execute(final ClientRegistration registration) {
        if (registration.usesImplicit()) {
            throw new ImplicitClientRefusedException(registration.clientId());
        }
        if (clientRegistrationRepository.findByClientId(registration.clientId()).isPresent()) {
            throw new ClientAlreadyExistsException(registration.clientId());
        }
        if (!registration.usesClientSecret()) {
            clientRegistrationRepository.save(registration, null);
            return new CreatedClient(registration, null);
        }
        final var secret = clientSecretGenerator.generate();
        clientRegistrationRepository.save(registration, passwordHasher.encode(secret));
        return new CreatedClient(registration, secret);
    }

Client authentication settings

A client also carries the settings of the stronger authentication methods (see Client credentials and service-to-service calls): jwkSetUrl and jwks (a public JWK set; a key with private material is refused with 400 invalid-jwks), tokenEndpointAuthSigningAlgorithm, tlsClientAuthSubjectDn and certificateBoundAccessTokens. A confidential client gets a generated secret only when one of its authentication methods is a client_secret_* one; a private_key_jwt or mTLS client has none. tls_client_auth requires a subject DN, self_signed_tls_client_auth and private_key_jwt require jwks or jwkSetUrl.

        jwkSetUrl:
          type: string
          format: uri
          description: >-
            URL of the client's public JWK set, used to verify private_key_jwt assertions and self-signed
            certificates. Absent means none.
        jwks:
          type: object
          description: >-
            The client's public JWK set (an object with a keys array), alternative to jwkSetUrl. Only public keys
            are accepted: a key with private material is refused with 400 invalid-jwks. Absent means none.
          additionalProperties: true
        tokenEndpointAuthSigningAlgorithm:
          type: string
          description: JWS algorithm a client signs its private_key_jwt assertions with.
          enum: [ RS256, RS384, RS512, ES256, ES384, ES512, PS256, PS384, PS512 ]
        tlsClientAuthSubjectDn:
          type: string
          description: >-
            Expected subject distinguished name of the certificate of a tls_client_auth client, for example
            CN=client,O=Example. Required by tls_client_auth.
        certificateBoundAccessTokens:
          type: boolean
          description: >-
            Whether the access tokens issued to the client are bound to its mutual TLS certificate (cnf x5t#S256).
            Defaults to false.
          default: false

The administration API refuses the implicit grant type (400): only the demo client of the opt-in legacy-implicit profile has it (see Implicit flow (legacy demo) and PAR), seeded at startup, public, with no PKCE and no consent. A private_key_jwt client with a registered jwks must also give tokenEndpointAuthSigningAlgorithm.

Dynamic client registration

OpenID Connect dynamic client registration (/connect/register) is supported by Spring Authorization Server and is off by default. Set authserver.oidc.client-registration.enabled=true to enable it; callers then need an initial access token with scope client.create.

    /**
     * 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()));
    }