【发布时间】:2020-06-30 08:42:09
【问题描述】:
我正在尝试从授权服务器授权我的资源服务器 api。 我的资源服务器包含以下配置。 现在我想测试 check_token 端点,但它总是返回未经授权的错误。 我在请求标头中传递授权对象(如您在下面的屏幕截图中所见。)
@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Override
public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
resources.resourceId("adminProfile").authenticationManager(authenticationManagerBean())
.tokenExtractor(new CustomTokenExtractor());
}
@Primary
@Bean
public RemoteTokenServices tokenService() {
RemoteTokenServices tokenService = new RemoteTokenServices();
tokenService.setCheckTokenEndpointUrl(
"http://localhost:8080/oauth/check_token");
tokenService.setClientId("clientId");
tokenService.setClientSecret("secretId");
return tokenService;
}
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
OAuth2AuthenticationManager authenticationManager = new OAuth2AuthenticationManager();
authenticationManager.setTokenServices(tokenService());
return authenticationManager;
}
}
【问题讨论】:
-
我知道它很旧。您的授权服务器配置是什么?以上代码仅显示资源服务器配置。 /oauth/check_token 端点需要在 Auth Server 端可访问。
-
是的,我的授权服务器实现很旧,问题是未启用检查令牌。
标签: spring spring-security spring-security-oauth2