0

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 年研究它,肯定会有某种方法......无论如何,我目前的要求只是访问谷歌 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,即使我的新参数一直在数据中,直到它被发送我得到一个不包含它们的网址

调试控制台的屏幕截图,显示 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 ?

4

1 回答 1

0
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));
      }
    });
};
于 2016-04-05T16:15:22.667 回答