【问题标题】:Spring security OAuth2 token introspectionSpring security OAuth2 令牌自省
【发布时间】:2020-07-20 15:47:16
【问题描述】:

我尝试使用 Spring 安全性通过自省来验证 OAuth2 令牌。 实际上,当我调用控制器时,我的应用程序不会尝试访问 OAuth 服务器进行自省并返回 403。

我的会议:

spring.security.oauth2.resourceserver.opaquetoken.introspection-uri=https://example.net/introspection
spring.security.oauth2.resourceserver.opaquetoken.client-id=clientId
spring.security.oauth2.resourceserver.opaquetoken.client-secret=clientSecret

网络安全:

@EnableWebSecurity
public class WebServerConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.oauth2ResourceServer().opaqueToken();
    }
}

我的控制器:

@RestController
public class Controller {

    @PostMapping(value = "/foo", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseStatus(HttpStatus.CREATED)
    public void uploadMedia(BearerTokenAuthentication bearerTokenAuthentication,
                        @RequestHeader(value = "Authorization") String bearerToken){

        System.out.println(bearerTokenAuthentication.getToken().getTokenValue());
    }
}

如何使用spring security通过自省验证OAuth令牌?

马修

【问题讨论】:

  • 我也在尝试,您找到解决方案了吗?

标签: spring security oauth token introspection


【解决方案1】:

尝试添加下面的依赖

<dependency>
    <groupId>org.springframework.security.oauth.boot</groupId>
    <artifactId>spring-security-oauth2-autoconfigure</artifactId>
    <version>2.1.8.RELEASE</version>
</dependency>

并且在应用程序属性中,您可以指定

security.oauth2.resource.token-info-uri=http://localhost:8080/oauth/check_token.

现在,核心类 - RemoteTokenServices.loadAuthentication 将用于调用授权服务器。 可以调试一下。

security.oauth2.client.client-id=client1
security.oauth2.client.client-secret=secret1

【讨论】:

    猜你喜欢
    • 2015-08-26
    • 2016-08-12
    • 1970-01-01
    • 2014-11-05
    • 2018-12-01
    • 2015-02-11
    • 1970-01-01
    • 2018-02-05
    • 2017-08-03
    相关资源
    最近更新 更多