【问题标题】:How do you set include_granted_scopes=true using Google's Java OAuth client?如何使用 Google 的 Java OAuth 客户端设置 include_granted_scopes=true?
【发布时间】:2014-11-10 02:23:25
【问题描述】:

我已成功使用 GoogleAuthorizationCodeFlow 获取和存储凭据以访问 Google 日历 API。我想为incremental authorization 使用include_granted_scopes=true 查询参数。

我搜索了很长时间,但无法弄清楚如何包含include_granted_scopes 参数。有办法吗?

【问题讨论】:

    标签: google-oauth-java-client


    【解决方案1】:

    首先获取您的授权网址

    GoogleAuthorizationCodeRequestUrl authUrl = googleAuthorizationCodeFlow.newAuthorizationUrl();
    

    授权url只是GenericUrl的一个实例,所以你可以使用GenericUrl.set(key, value)来设置任意查询参数。

    authUrl.set("include_granted_scopes", true);
    

    【讨论】:

      【解决方案2】:

      尝试以下方法:

      var googleOAuthOptions = 
          new GoogleOAuth2AuthenticationOptions()
          {
              ClientId = "...",
              ClientSecret = "...",
      
              Provider = new GoogleOAuth2AuthenticationProvider
                          {
                              OnApplyRedirect = context =>
                              {
                                  var redirect = context.RedirectUri;
                                  redirect += "&include_granted_scopes=true";
                                  context.Response.Redirect(redirect);
      
                              }
                          }
          };
      
      googleOAuthOptions.Scope.Add(...);
      
      app.UseGoogleAuthentication(googleOAuthOptions);
      

      【讨论】:

        猜你喜欢
        • 2018-05-25
        • 2013-11-07
        • 1970-01-01
        • 2014-05-07
        • 2014-12-08
        • 2020-09-19
        • 1970-01-01
        • 1970-01-01
        • 2023-03-12
        相关资源
        最近更新 更多