ClientDetailsService is an interface from the legacy Spring Security OAuth 2 project (org.springframework.security.oauth2.provider) that an OAuth 2 authorization server used to look up a registered client by its client id. It returned a ClientDetails object holding the secret, scopes, grant types and redirect URIs that the server needed to authenticate and authorise that client.
That project reached end of life and is not used for new work. Today the same role is played by RegisteredClientRepository in Spring Authorization Server, so this article explains the old interface and shows the modern replacement.
In an OAuth 2 flow, the client application (a web app, a mobile app or a backend job) must be known to the authorization server before it can ask for tokens. ClientDetailsService had a single method:
During /oauth/token and /oauth/authorize requests, the server called this method with the client id and then checked the secret, the requested grant type, the scope and the redirect URI against the returned ClientDetails. If the client was unknown, it threw NoSuchClientException.
The old library shipped two implementations:
| Implementation | Storage | Use |
|---|---|---|
InMemoryClientDetailsService | In memory | Samples and tests |
JdbcClientDetailsService | A SQL table (oauth_client_details) | Persistent clients |
A typical legacy configuration extended AuthorizationServerConfigurerAdapter:
The library also supported the implicit and password grants. Both are removed from the OAuth 2.1 draft because they are insecure, so avoid them in new designs.
Spring Security OAuth 2 was deprecated in 2019 and its maintenance ended in 2022. The Spring team moved authorisation server support to the separate Spring Authorization Server project, which is built on the Spring Security 6 and 7 stack. Its model differs:
| Legacy | Current |
|---|---|
ClientDetailsService | RegisteredClientRepository |
ClientDetails | RegisteredClient |
JdbcClientDetailsService | JdbcRegisteredClientRepository |
@EnableAuthorizationServer | SecurityFilterChain with OAuth2AuthorizationServerConfigurer |
| Password and implicit grants | Authorization code with PKCE, client credentials, refresh token |
If you only need an OAuth 2 client or resource server, you do not need a custom authorization server at all. Spring Security covers those natively, and many teams delegate to a provider such as Keycloak.
This is the modern equivalent of the legacy configuration above. It uses the spring-boot-starter-oauth2-authorization-server dependency.
For persistence, use JdbcRegisteredClientRepository with the schema scripts the project provides, or implement RegisteredClientRepository against your own store. It has save, findById and findByClientId, so the lookup by client id works as loadClientByClientId did.
PasswordEncoder.ClientDetails row to a RegisteredClient and move to the new endpoints.No. It belongs to the end-of-life Spring Security OAuth 2 project. Use RegisteredClientRepository from Spring Authorization Server.
ClientDetails describes an OAuth 2 client application, while UserDetails describes an end user. The authorization server uses the first to authenticate the client and the second to authenticate the person.
No. A resource server only validates access tokens. Client registration is the authorization server's concern.
Use JdbcRegisteredClientRepository or write your own implementation of RegisteredClientRepository.
ClientDetailsService was the lookup point for registered OAuth 2 clients in the old Spring Security OAuth 2 project. It is obsolete. In current Spring applications, register clients through RegisteredClientRepository and RegisteredClient, prefer authorization code with PKCE, and keep secrets encoded and scopes narrow.