【问题标题】:How to set access_type=offline using spring boot security and oauth flow to generate a refresh tokenn如何使用 Spring Boot 安全性和 oauth 流设置 access_type=offline 以生成刷新令牌
【发布时间】:2021-11-07 18:35:30
【问题描述】:

我正在使用 Sprint boot security + OAuth2 with google 来与 google 集成。我已使用以下属性在 InMemoryClientRegistrationRepository 中将 google 注册为 oauth2 客户端。

private ClientRegistration googleClientRegistration() {
       Map<String ,Object> configMap = new HashMap<>();
       configMap.put("access_type","offline");
       return ClientRegistration.withRegistrationId("g_mail")
               .clientId(googleClientId)
               .clientSecret(googleSecret)
               .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
               .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
               .redirectUri(redirectURI.replace("source", "G_MAIL"))
               .scope("openid","email","profile","https://www.googleapis.com/auth/contacts.readonly","https://www.googleapis.com/auth/gmail.readonly","https://www.googleapis.com/auth/calendar.readonly")
               .authorizationUri("https://accounts.google.com/o/oauth2/v2/auth")
               .tokenUri("https://www.googleapis.com/oauth2/v4/token")
               .providerConfigurationMetadata(configMap)
               .userInfoUri("https://www.googleapis.com/oauth2/v3/userinfo")
               .userNameAttributeName(IdTokenClaimNames.SUB)
               .jwkSetUri("https://www.googleapis.com/oauth2/v3/certs")
               .clientName("Google").build();
   }

用户成功授权和认证后,我们在回调处理程序中收到授权码。使用此授权代码生成访问令牌时,我无法获取刷新令牌。你能帮我解决这个问题吗?提前致谢。

注意:- 我已将这些客户端注册存储库配置为 bean。因为我们将使用这些访问令牌来访问用户的数据。如果您需要更多输入,请告诉我。

【问题讨论】:

    标签: spring-boot spring-security-oauth2


    【解决方案1】:

    我自己解决了。以下是我的解决方案。我已经更新了授权 api 并且它工作了

    authorizationUri("https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=consent")

    【讨论】:

      猜你喜欢
      • 2013-09-02
      • 1970-01-01
      • 2020-02-17
      • 2019-01-16
      • 2020-02-08
      • 2018-10-16
      • 2017-12-25
      • 2017-10-27
      • 2020-07-18
      相关资源
      最近更新 更多