Java 在重定向之前为spring.security.oauth2.client中的授权Url添加请求参数
我目前有一个网关应用程序,它使用Netty服务器和OAuth2以及网关。目前,它正在使用Java 在重定向之前为spring.security.oauth2.client中的授权Url添加请求参数,java,spring-security,spring-webflux,Java,Spring Security,Spring Webflux,我目前有一个网关应用程序,它使用Netty服务器和OAuth2以及网关。目前,它正在使用ReactiveClientRegistrationRepository、@EnableWebFluxSecurity和ServerHttpSecurity来配置安全性 目前,my application.yml如下所示: spring: profiles: local autoconfigure: #TODO: track issue https://github.com/spring-projec
ReactiveClientRegistrationRepository
、@EnableWebFluxSecurity
和ServerHttpSecurity
来配置安全性
目前,my application.yml如下所示:
spring:
profiles: local
autoconfigure: #TODO: track issue https://github.com/spring-projects/spring-security/issues/6314
exclude: org.springframework.boot.actuate.autoconfigure.security.reactive.ReactiveManagementWebSecurityAutoConfiguration
security:
oauth2:
client:
registration:
azure:
provider: azure
client-id: ...
client-secret: ...
authorization-grant-type: authorization_code
redirect-uri-template: "{baseUrl}/login/oauth2/code/{registrationId}"
scope: ...
provider:
azure:
authorization-uri: https://login....com/oauth2/authorize
token-uri: https://login.com/oauth2/token
user-info-uri: https://login.com/openid/userinfo
jwk-set-uri: https://login.com/discovery/keys
issuer-url: https://login.com/
user-name-attribute: upn
我需要添加一个查询参数(除了范围和状态等默认值)。这可能是
“”
我已经尝试添加一个过滤器来更改位置和添加查询参数,以及将查询参数添加到yml文件中的授权url
后者导致错误:因为url中现在有2个?
在“true”响应中查询参数的字符“=”无效\u type=code”
@启用WebFluxSecurity
公共类SecurityConfig{
@值(${content.security.policy}”)
私有字符串内容安全策略;
@豆子
公共安全WebFilterChain配置(ServerHttpSecurity http){
返回http
.授权交易所()
.anyExchange().authenticated()
.and().oauth2Login()
.and().headers().contentSecurityPolicy(contentSecurityPolicy)。and()
.和().build();
}
@配置
公共类OAuthWebClientConfig{
@豆子
网络客户端网络客户端(ReactiveClientRegistrationRepository clientRegistrationRepository,
服务器OAuth2AuthorizedClientPository(授权客户存储){
服务器OAuth2AuthorizedClientExchangeFilterFunction oauth=
新服务器OAuth2AuthorizedClient ChangeFilterFunction(clientRegistrationRepository,AuthorizedClient存储库);
//(可选)显式选择使用oauth2Login隐式提供访问令牌
setDefaultOAuth2AuthorizedClient(true);
返回WebClient.builder()
.filter(oauth)
.build();
}
build.gradle依赖项
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.bitbucket.b_c:jose4j:0.5.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'commons-codec:commons-codec:1.11'
implementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner'
implementation 'io.reactivex:rxjava:1.3.8'
implementation 'org.springframework.boot:spring-boot-configuration-processor'
implementation 'com.google.guava:guava:23.5-jre'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-client', version: '2.1.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-security', version: '2.1.2.RELEASE'
compileOnly 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.microsoft.azure:adal4j:1.6.4'
}
预期:
授权URL是使用常规查询参数生成的,例如:redirect_uri、scope、state和自定义参数,例如示例中的idp
实际:
添加到yml文件会导致“true”响应中查询参数的错误无效字符“=”
ServerHttpSecurity上的oauth2Login()无法轻松覆盖授权url。有什么方法吗