【问题标题】:Spring OAuth testing /oauth/check_token through postmanSpring OAuth 通过邮递员测试 /oauth/check_token
【发布时间】: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


【解决方案1】:

阅读文档后,我发现需要在配置中添加启用检查令牌的标志。

<oauth:authorization-server check-token-enabled="true" client-details-service-ref="clientDetails" token-services-ref="tokenServices" user-approval-handler-ref="userApprovalHandler" >
        <oauth:authorization-code/>
        <oauth:implicit />
        <oauth:refresh-token />
        <oauth:client-credentials/>
        <oauth:password />
    </oauth:authorization-server>

【讨论】:

    猜你喜欢
    • 2020-09-05
    • 2019-12-01
    • 2018-09-08
    • 2018-05-04
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 2019-10-26
    • 2015-04-22
    相关资源
    最近更新 更多