Spring 5 + WebFlux 安全 + JWT 令牌

Spring 5 + WebFlux Security + JWT tokens

在我们使用 Spring Boot 2 starters + Spring 5.0.7 + Reactor (WebFlux) 的项目中,我们想实现安全性使用 Spring 安全性。仅包括开胃菜:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

还有豆子:

@Bean
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) throws Exception {
    return http.authorizeExchange()
            .anyExchange().authenticated()
            .and().build();
    }

绰绰有余。

但是,我们想使用 JWT 令牌(在另一方,在资源服务器中生成)来拦截那些 Authorization headers。我一直在为此苦苦挣扎,找不到 Spring 5 的任何示例(而 Spring <5 有很多示例和教程)。

有人遇到过这个问题吗?

8 月 29 日发布了新的 Spring 版本:5.1。这个版本修复了这个问题。提交实现这是 this. The example of how to use it can be checked here.