配置 Spring Security 5 Oauth 2 以使用 access_token uri 参数

Pus*_*kar 3 spring spring-security spring-boot spring-security-oauth2 spring-webflux

我正在基于此示例创建一个应用程序 -

背景 -

https://github.com/spring-projects/spring-security/tree/master/samples/boot/oauth2resourceserver-webflux

OAuth2 令牌位于标头中,它工作得很好。

问题 -

但是我想将其更改为在 url 中使用 OAuth 2 令牌。我正在尝试创建 OAuth2 资源服务器。

分析-

Spring Security 似乎支持从 access_token 参数获取令牌 -

https://github.com/spring-projects/spring-security/blob/e3eaa99ad06769cf44ad3e1249f6398077b90834/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/server/ ServerBearerTokenAuthenticationConverter.java#L57

但它似乎默认被禁用 -

https://github.com/spring-projects/spring-security/blob/master/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/web/server/ ServerBearerTokenAuthenticationConverter.java#L48

现在,在此处直接创建的 spring 层次结构之外无法访问该类 -

https://github.com/spring-projects/spring-security/blob/master/config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java#L955

问题?

在我的代码中是否可以将此allowUriQueryParameter设置为true?

更新

我正在创建一个 OAuth2 资源服务器。不幸的是,OAuth2ResourceServerSpec 不允许设置authenticationConverter。

Joã*_*nte 7

Pushkar 的答案对我不起作用,但帮助我找到了解决方案,以下代码成功了:

DefaultBearerTokenResolver resolver = new DefaultBearerTokenResolver();
resolver.setAllowUriQueryParameter(true);

http.authorizeRequests()
        .anyRequest().authenticated()
        .and().oauth2ResourceServer().bearerTokenResolver(resolver)
        .jwt();
Run Code Online (Sandbox Code Playgroud)

谢谢。


归档时间:

查看次数:

4502 次

最近记录:

4 年 前