How to configure Spring OAuth 2.0 security client store for a database

I found a tutorial about Spring REST Service OAuth at https://github.com/royclarkson/spring-rest-service-oauth

But I am wondering how to set up a client stored in a database, so I can easily manage it. In the test repository of the inMemory client configuration in the OAuth2ServerConfiguration.java class

@Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { // @formatter:off clients.inMemory().withClient("clientapp") .authorizedGrantTypes("password", "refresh_token") .authorities("USER").scopes("read", "write") .resourceIds(RESOURCE_ID).secret("123456"); // @formatter:on } 
+7
spring-security spring-security-oauth2
source share
2 answers
0
source share

@OhadR thank you for your reply, really appreciate it!

I actually found the answer through this thread: error in Spring AuthorizationServerConfigurerAdapter when assigning Jdbc data store for ClientDetailsService

To do this, I need only two steps:

  • create a table representing client data
  CREATE TABLE oauth_client_details ( client_id VARCHAR(256) PRIMARY KEY, resource_ids VARCHAR(256), client_secret VARCHAR(256), scope VARCHAR(256), authorized_grant_types VARCHAR(256), web_server_redirect_uri VARCHAR(256), authorities VARCHAR(256), access_token_validity INTEGER, refresh_token_validity INTEGER, additional_information VARCHAR(4096), autoapprove VARCHAR(256) ); 
  1. specific jdbc configuration
 DataSource dataSource = DataSourceBuilder.create() .driverClassName("com.mysql.jdbc.Driver") .url("jdbc:mysql://localhost:3306/gsrestdb").username("***").password("***").build(); clients.jdbc(dataSource); 
+6
source share

All Articles