簡體   English   中英

Spring 安全 OAuth2 令牌自省

[英]Spring security OAuth2 token introspection

我嘗試通過自省使用 Spring 安全性來驗證 OAuth2 令牌。 實際上,當我調用 controller 時,我的應用程序不會嘗試訪問 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();
    }
}

我的 Controller:

@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 安全性來有效的 OAuth 令牌?

馬修

嘗試添加以下依賴項

<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.

現在,核心 class - RemoteTokenServices.loadAuthentication 將用於調用授權服務器。 你可以把它放在調試中。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM