我在https://github.com/royclarkson/spring-rest-service-oauth
上找到了关于Spring REST Service OAuth的教程但是我想知道如何配置存储到数据库的客户端,所以我可以轻松管理。 在课程OAuth2ServerConfiguration.java中的教程客户端配置存储inMemory中
@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
}
答案 0 :(得分:8)
我通过这个帖子实际找到了答案:error in Spring AuthorizationServerConfigurerAdapter when assigning Jdbc datastore to ClientDetailsService
要做到这一点,我只需要两步:
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)
);
DataSource dataSource = DataSourceBuilder.create()
.driverClassName("com.mysql.jdbc.Driver")
.url("jdbc:mysql://localhost:3306/gsrestdb").username("***").password("***").build();
clients.jdbc(dataSource);
答案 1 :(得分:1)