Identity Toolkit for Websites v3 提供授权代码 signInSuccess 回调 tokenString 参数。
虽然//www.gstatic.com/authtoolkit/js/gitkit.js 是混淆和无文档的,但我发现了 .gstatic.com/authtoolkit/js/gitkit-debug.js这应该会有所帮助,但我仍然好奇是否有更好的方法,或者我是否错过了什么。
问题是我找不到设置参数的方法 access_type=离线,所以我无法获得刷新令牌,因此使用 Java 的 Google API 客户端库,使用 idp google.com 登录后似乎不是一种选择。我无法将其与提供的联合登录解决方案一起使用。我需要单独实现谷歌提供商 oauth 流程......我不敢相信我一定在这里错过了什么。
如果我不能使用它来访问其他谷歌 API,那么在 url # 中提供对授权代码的访问有什么意义。
无论如何,早在 2012 年,有人就有同样的问题,为 [this][2] 论坛讨论中看到的 v1 提供了解决方案。
响应以"不同的 IdP 有不同的方法来获取刷新令牌,即,对于Microsoft,需要"wl.offline_access"范围;对于 Google,"access_type=离线"网址参数是必需的。目前GITKit还没有一个规范化的方法,但我们正在研究它。
如果他们在 2012 年对此进行调查,肯定有某种方法......无论如何,我目前的要求只是访问谷歌API。
因此,比较谷歌oauth游乐场的流程,您可以在其中选择access_type=离线,并且帐户选择器网址继续...看起来像这样
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
<mpl=popup
&btmpl=authsub
&hl=en_GB
&scc=1
&oauth=1
在哪里可以看到access_type参数。我在所有正确的位置向 gitkit-debug 添加了一些额外的配置属性.js然后跟踪执行步骤到函数中,直到发送 POST,即使我的新参数一直在数据中,直到它被发送我得到一个不包括它们的 url
调试控制台的尖叫声,在开机自检前显示数据对象状态
我生成的 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
<mpl=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));
}
});
};