Skip to content

Instantly share code, notes, and snippets.

@jei0486
Created January 10, 2023 02:22
Show Gist options
  • Save jei0486/8fcbdf498f7ef7fe7c4cbb51f91851f2 to your computer and use it in GitHub Desktop.
Save jei0486/8fcbdf498f7ef7fe7c4cbb51f91851f2 to your computer and use it in GitHub Desktop.
opaque-token-Spring-Security
package com.demo.scg.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
@Configuration
@EnableWebFluxSecurity
public class SecurityConfig {
    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        // oauth2 Resource
        http.authorizeExchange(exchanges -> exchanges.anyExchange().authenticated())
                .oauth2ResourceServer(oauth2 -> oauth2
                        .opaqueToken(opaqueToken -> opaqueToken
                                .introspectionUri("http://localhost:8080/auth/realms/demo/protocol/openid-connect/token/introspect")
                                .introspectionClientCredentials("demo-client", "83f3e948-3f8c-49da-af7f-87a42d5ea6fd")
                        )
                );
        http.csrf().disable();
        return http.build();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment