Java 如何在DefaultOAuth2AuthorizationRequestResolver上设置AuthorizationRequestCustomizer?
在尝试让Spring Security OAuth2 5.4.2使用自定义作用域和授权代码流中的Auth0时。我无意中发现了一个我没有简单解决办法的小细节 要请求自定义作用域,Auth0要求用户提供Java 如何在DefaultOAuth2AuthorizationRequestResolver上设置AuthorizationRequestCustomizer?,java,spring,spring-security,spring-security-oauth2,auth0,Java,Spring,Spring Security,Spring Security Oauth2,Auth0,在尝试让Spring Security OAuth2 5.4.2使用自定义作用域和授权代码流中的Auth0时。我无意中发现了一个我没有简单解决办法的小细节 要请求自定义作用域,Auth0要求用户提供访问群体。重定向URI是在org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizationRequestResolver#resolve(javax.servlet.http.HttpServletRequest,jav
访问群体
。重定向URI是在org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizationRequestResolver#resolve(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String)
中创建的
可以使用
授权请求定制程序修改此流程,但是,我没有看到任何注入自定义程序的方法,DefaultOAuth2AuthorizationRequestResolver
没有注册为bean,或者至少我不知道如何访问它。您可以实现自定义OAuth2AuthorizationRequestResolver,然后将其添加到spring安全配置中
.oauth2Login(req->
req.authorizationEndpoint()
.authorizationRequestResolver(new YourCustomAuthorizationRequestResolver)
)
你能提供更多关于这个问题的信息吗?我知道,在Spring Security中配置Auth0没有任何问题。它很容易复制:尝试访问为Auth0中配置的API创建的自定义范围,例如“创建:项目”。现在尝试通过授权代码流使用该范围。它无法工作,因为Auth0需要一个查询参数&acquisition=
,如果没有AuthorizationRequestCustomizer
修补请求,Spring Security将无法提供该参数。问题不是我无法配置Auth0,但是我不能使用自定义范围。不幸的是,仅仅设置AuthorizationRequestCustomizer
并不是一个简单的方法,相反,我必须通过获取ClientRegistrationRepository
和自动化请求基URI来替换整个authorizationRequestResolver
。使用参数化的DefaultOAuth2AuthorizationRequestResolver
使用authorizationRequestResolver.setAuthorizationRequestCustomizer(b->b.additionalParameters(Map.of(“受众”)和http://localhost:8080/")));代码>