Mar*_* M. 6 google-cloud-endpoints google-oauth
当您使用Google Cloud Endpoints进行身份验证时,如果已登录多个Google帐户,但已经授予了您的应用权限,则只需选择默认帐户,就像Gmail一样.
1)Gmail可以在右上角切换Google帐户.我将如何实现类似的目标?
2)即使用户已经登录,您是否可以要求用户再次登录其Google帐户?与用户更改帐户设置时类似.
我找到了一种方法,但有点遗憾的是此功能未包含(或未记录)在gapi.auth.authorize.
无论如何,如果您手动打开授权弹出窗口,然后处理生成的令牌,您可以传递其他参数,例如prompt=select_account,这将允许用户选择他们的帐户。
这是一个代码示例。使用弹出窗口阻止功能,您必须在onclick事件中调用此函数才能阻止弹出窗口。
因此,该代码还没有真正适合生产。我们不管理用户拒绝同意等情况,也不传递过期时间等额外的令牌信息。
var switchUserAccount = function (callback) {
var popup = window.open("https://accounts.google.com/o/oauth2/auth?client_id=102862643449-geb89aoann7dj6tsha4mtkhvos5mk01b.apps.googleusercontent.com"
+ "&prompt=select_account"
+ "&scope=https://www.googleapis.com/auth/userinfo.email"
+ "&redirect_uri=https://david-sandbox.appspot.com/autoclose.html"
+ "&access_type=online&response_type=token", "thewindow");
var waitForPopup = function () {
try {
var token = popup.location.hash.substring(14).split("&")[0];
console.log("FOund token !" + token);
if (token == "") {
console.log("Not ready yet")
setTimeout(waitForPopup, 500);
} else {
gapi.auth.setToken({access_token: token});
popup.close();
callback();
}
}
catch (e) {
console.log("Not ready yet, exception")
setTimeout(waitForPopup, 500);
}
};
waitForPopup();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
156 次 |
| 最近记录: |