We already discussed how to configure an OAuth 2.0 authentication and how to build a custom token store. In the last article of this series, you will learn how to implement a custom dynamic client registration using spring-security-oauth2. I recommend you reading Part 1 and Part 2 first,  as we are going to continue from where we have left off.

Let’s start by creating the entity responsible for storing the client data:

Here is the respective repository:


Now, we can implement the ClientDetailsService interface from the spring security class:


Note that I’m using the BaseClientDetails class rather than implementing the ClientDetails interface. It seems to be the best option, as even the standard JDBC implementation uses it.

Finally, we need to change our AuthorizationServerConfig to use our CouchbaseClientDetailsService:

Here is how the whole class looks:


Now you can simply insert a new client into your database and use these credentials to authenticate via OAuth:


TL;DR – The trick is to implement the org.springframework.security.oauth2.provider.ClientDetailsService interface and pass it as a parameter to your ClientDetailsServiceConfigurer:


If you have any questions, tweet me at @deniswsrosa


Posted by Denis Rosa, Developer Advocate, Couchbase

Denis Rosa is a Developer Advocate for Couchbase and lives in Munich - Germany. He has a solid experience as a software engineer and speaks fluently Java, Python, Scala and Javascript. Denis likes to write about search, Big Data, AI, Microservices and everything else that would help developers to make a beautiful, faster, stable and scalable app.

Leave a reply