簡體   English   中英

Spring 5 Oauth2 - 如何在我的資源服務器中提供校驗令牌 URL?

[英]Spring 5 Oauth2 - How to provide the check token URL in my Resource server?

我需要協助..

我使用來自 Spring-security-oauth2 的@EnableAuthorizationServer為授予類型“client_credentials”設置了一個AuthorizationServer 能夠創建、檢查令牌以及所有與此相關的好東西。

/oauth/令牌
/oauth/checkToken

按照此示例進行授權服務器

我有一個單獨的項目,其中包含要保護的 REST API。 我不能使用@EnableResourceServer ,因為該項目使用 Spring 5.2.8 和 spring-security-oauth2 2.5 導致沖突(因為它使用 4.x Spring jars 並且排除它們會導致更多問題),同時通過 Weblogic 進行部署,所以我我正在使用這個樣本

現在,在此示例中,我如何只提供 Checktoken url。此示例需要 JWT json 類型的文件,但我沒有。 我只是想保持簡單並使用我創建的授權服務器的檢查令牌 url,類似於@EnableResourceServer的工作方式。(就像這里提供的,除了沒有@EnableResourceServer

我在哪里提供? 任何直接的幫助表示贊賞。

按照您的 ResourceServer 示例,這對我有用:

@EnableWebSecurity
public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Value("${security.oauth2.resource.tokenInfoUri}") String tokenInfoUri;
    @Value("${security.oauth2.client.clientId}") String clientId;
    @Value("${security.oauth2.client.clientSecret}") String clientSecret;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        http
                .authorizeRequests((authorizeRequests) ->
                        authorizeRequests
                                .antMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
                                .antMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
                                .anyRequest().authenticated()
                )
                .oauth2ResourceServer(OAuth2ResourceServerConfigurer::opaqueToken);
        // @formatter:on
    }

    @Bean
    OpaqueTokenIntrospector opaqueTokenIntrospector() {
        return new NimbusOpaqueTokenIntrospector(tokenInfoUri,clientId,clientSecret);
    }
}

我使用了以下 spring 安全依賴項:

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>5.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-jose</artifactId>
            <version>5.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.nimbusds</groupId>
            <artifactId>oauth2-oidc-sdk</artifactId>
            <version>8.22</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-resource-server</artifactId>
            <version>5.3.4.RELEASE</version>
        </dependency>

將您的 checkToken-Uri、client 和 clientSecret 放入您的 application.properties。

我最終使用了Spring提供的JWT樣本,得到了JWT公鑰在資源服務器上進行驗證。 遵循 Spring 源示例項目中提供的身份驗證和資源服務器。

到目前為止工作良好,直到我們遷移到更好的 IDM 解決方案

暫無
暫無

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

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