Identity Toolkit for Websites v3 添加 access_type=offline 以继续参数值?

Identity Toolkit for Websites v3 add access_type=offline to continue param value?

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、post 使用 idp google.com 似乎不是一个选项。 我不能将它与提供的联合登录解决方案一起使用。我需要单独实施 google 提供商 oauth 流程……我不敢相信我一定在这里遗漏了一些东西。

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

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

The response starts with "Different IdP has different ways to get a refresh token, i.e., for Microsoft, a "wl.offline_access" scope is required; for Google, an "access_type=offline" URL parameter is required. Currently GITKit has'目前还没有标准化的方法来做到这一点,但我们正在研究它。"

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

所以比较 google oauth playground 的流程,你可以 select 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 被发送,即使我的新参数一直在数据中直到它被发送我得到一个 url 其中不包括它们

screeenshot of debug console showing data object state just before POST

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

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=离线?

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));
      }
    });
};