我正在将OAuth2与Spring结合使用,并尝试从数据库中使用配置失败。
如果我这样做:
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory().withClient("clients").secret(encriptar.passwordEncoder().encode("1234"))
.authorizedGrantTypes("password", "refresh_token", "authorization_code").scopes("read,write,trust")
.accessTokenValiditySeconds(5).refreshTokenValiditySeconds(28800);
}
一切正常
但是,如果我尝试:
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(dataSource).passwordEncoder(encriptar.passwordEncoder());
}
当我尝试访问端点/ oauth / token时, 我得到了错误
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
我的设置
@Table(name = "oauth_client_details")
public class Token {
@Id
private String client_id;
private String cliente_secret;
private String resource_ids;
private String scope;
private String authorized_grant_types;
private String web_server_redirect_uri;
private String authorities;
private String access_token_validity;
private String refresh_token_validity;
private String additional_information;
private String autoapprove;
}
@Bean
public OAuth2RequestFactory requestFactory() {
CustomOauth2RequestFactory requestFactory = new CustomOauth2RequestFactory(clientDetailsService);
requestFactory.setCheckUserScopes(true);
return requestFactory;
}
@Bean
public TokenStore tokenStore() {
return new JwtTokenStore(jwtAccessTokenConverter());
}
@Bean
public TokenEndpointAuthenticationFilter tokenEndpointAuthenticationFilter() {
return new TokenEndpointAuthenticationFilter(authenticationManager, requestFactory());
}
我在做什么错了?