Spring security 带刷新令牌的Spring Google OAuth2
我当前的OAuth2配置没有返回刷新令牌。我的配置尽可能基本。如何对其进行配置,使其同时返回refresh_令牌。 我正在服务器端验证用户身份。所以JS解决方案不起作用 我需要用于记忆功能的刷新令牌。具体来说,我使用的是Spring security 带刷新令牌的Spring Google OAuth2,spring-security,google-oauth,spring-oauth2,Spring Security,Google Oauth,Spring Oauth2,我当前的OAuth2配置没有返回刷新令牌。我的配置尽可能基本。如何对其进行配置,使其同时返回refresh_令牌。 我正在服务器端验证用户身份。所以JS解决方案不起作用 我需要用于记忆功能的刷新令牌。具体来说,我使用的是oAuth2AuthorizedClientService.loadAuthorizedClient(clientId,principalName)方法,以访问从Google身份验证服务器检索到的信息 WebSecurityConfigurerAdapter { ... h
oAuth2AuthorizedClientService.loadAuthorizedClient(clientId,principalName)代码>方法,以访问从Google身份验证服务器检索到的信息
WebSecurityConfigurerAdapter {
...
httpSecurity
...
.and()
.oauth2Login()
.and()
.rememberMe()
...
Application.yml:
security:
oauth2:
client:
registration:
google:
clientId: ZZZ
clientSecret: zzzz
redirectUri: https://example.com/login/oauth2/code/google
我的解决办法是增加
在OAuth2AuthorizationRequestResolver
中,我更改了customAuthorizationRequest
(见下文)。现在它每次都返回刷新令牌
private OAuth2AuthorizationRequest customAuthorizationRequest( OAuth2AuthorizationRequest authorizationRequest) {
Map<String, Object> additionalParameters =new LinkedHashMap<>(authorizationRequest.getAdditionalParameters());
additionalParameters.put("access_type", "offline");
return OAuth2AuthorizationRequest.from(authorizationRequest)
.additionalParameters(additionalParameters)
.build();
}
如果有人找到更简单的解决方案,请发帖子!:)
.oauth2Login()
.authorizationEndpoint()
.authorizationRequestResolver(
new CustomAuthorizationRequestResolver(
this.clientRegistrationRepository))
.and()
.and()
.rememberMe()