【问题标题】:Identity Toolkit for Websites v3 add access_type=offline to continue param value?Identity Toolkit for Websites v3 添加 access_type=offline 以继续参数值?
【发布时间】:2016-07-06 08:47:08
【问题描述】:

Identity Toolkit for Websites v3 提供授权码 signInSuccess 回调 tokenString 参数。

虽然 //www.gstatic.com/authtoolkit/js/gitkit.js 是模糊的和无证的,我发现 .gstatic.com/authtoolkit/js/gitkit-debug.js 这应该会有所帮助,但我仍然很好奇是否有更好的方法或者我是否遗漏了什么。

问题是我找不到设置参数 access_type=offline 的方法,所以我无法获得刷新令牌,因此使用Google API Client Library for Java,使用 idp google.com 登录后似乎不是一个选项。 我不能将它与提供的联合登录解决方案一起使用。我需要单独实现谷歌提供者 oauth 流程......我不敢相信我一定会在这里遗漏一些东西。

如果我不能使用它来访问其他 google api,那么在 url # 中提供对授权代码的访问有什么意义。

无论如何,早在 2012 年就有人遇到了同样的问题,在 [this][2] 论坛讨论中看到的 v1 提供了解决方案。

响应开头为“不同的 IdP 有不同的方式来获取刷新令牌,即,对于 Microsoft,需要一个“wl.offline_access”范围;对于 Google,需要一个“access_type=offline”URL 参数。目前是 GITKit还没有标准化的方法来做到这一点,但我们正在研究它。”

如果他们在 2012 年研究它,肯定有某种方法......无论如何,我目前的要求只是访问 google api。

所以比较 google oauth playground 的流程,您可以在其中选择 access_type=offline 和帐户选择器 url continue ... 看起来像这样

 https://accounts.google.com/AccountChooser?continue=https://accounts.google.com/o/oauth2/auth?
access_type=offline
&approval_prompt=force
&scope=https://www.googleapis.com/auth/cloudprint+https://www.googleapis.com/auth/userinfo.profile
&response_type=code
&redirect_uri=https://developers.google.com/oauthplayground
&client_id=407408718192.apps.googleusercontent.com
&hl=en-GB
&from_login=1
&as=5cc2df3c88f13395
&ltmpl=popup
&btmpl=authsub
&hl=en_GB
&scc=1
&oauth=1

您可以在哪里看到 access_type 参数。 我在所有正确的地方向 gitkit-debug.js 添加了一些额外的配置属性,然后跟踪执行步入函数直到发送 POST,即使我的新参数一直在数据中,直到它被发送我得到一个不包含它们的网址

screeenshot of debug console showing data object state just before POST

我得到的 url continue 参数看起来像这样

https://accounts.google.com/AccountChooser?continue=https://accounts.google.com/o/oauth2/auth?
scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/cloudprint+https://www.googleapis.com/auth/userinfo.profile+openid
&response_type=token+code+id_token+gsession
&redirect_uri=http://localhost:8080/identity/control/authenticate
&state=AFD_5tmV........... etc
&client_id=143312559437-4o93ranlfalg78rj006qirib182bnkj4.apps.googleusercontent.com
&include_profile=true
&hl=en-GB
&from_login=1
&as=77237587f41849c5
&ltmpl=popup
&btmpl=authsub
&hl=en_GB
&scc=1
&oauth=1

为什么以及如何删除 access_type=offline ?

【问题讨论】:

    标签: java google-oauth google-identity-toolkit google-identity


    【解决方案1】:
    gitkit.widget.handler.onProviderSignInIdpClick_ = function(app, component, idp) {
      //null values are removed later in requestGitkitEndpoint
      //not sure if extra paramaters are needed in the Request
      var request = {
        providerId: idp.getProviderId(),
        continueUri: app.getConfig().getIdpCallbackUrl(),
        oauthScope: app.getConfig().getIdpConfigAdditionalScopes(),
        access_type: app.getConfig().getAccessType(),
        approval_prompt: app.getConfig().getApprovalPrompt()
      };
      //the request is then parsed into the executor within component.executeRequest
      component.executeRequest(
        //executor
        goog.bind(app.getApi().createAuthUri, app.getApi()),
        //request
        request,
        //cb
        function(resp) {
          if (!resp || gitkit.api.hasError(resp)) {
            (gitkit.log.error("createAuthUri: " + goog.json.serialize(resp)), component.showInfoBar(gitkit.widget.handler.common.getErrorMessage(gitkit.api.getErrorCode(resp))))
          } else {
            if(resp.providerId === 'google.com'){
              var append = null;
              if (goog.isDefAndNotNull(app.getConfig().getAccessType())) {
                var paramValue = goog.string.urlEncode(app.getConfig().getAccessType());
                append = "&access_type=" + paramValue;
              }
              if (goog.isDefAndNotNull(app.getConfig().getApprovalPrompt())) {
                var paramValue = goog.string.urlEncode(app.getConfig().getApprovalPrompt());
                if(append) append = append.concat("&approval_prompt=" + paramValue);
                else append = "&approval_prompt=" + paramValue
              }
              if(append){
                resp.authUri = resp.authUri.concat(append);
              }
            }
            resp.sessionId && gitkit.storage.setSessionId(resp.sessionId, app.getAppId()),
              gitkit.storage.setRememberAccount(!1, app.getAppId()),
              gitkit.util.goTo(goog.asserts.assert(resp.authUri));
          }
        });
    };
    

    【讨论】:

      猜你喜欢
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-23
      • 2015-09-13
      • 1970-01-01
      • 2013-09-02
      • 2014-10-19
      • 2012-05-10
      相关资源
      最近更新 更多