use*_*212 6 authentication logging out google-plus
我目前正在尝试创建一个用户可以使用他的Google +帐户登录的网站.大多数都在工作.我让他们授予访问我的网站的权限.他们可以登录并获取他们的姓名和用户ID,并在我的网站上显示特定于他们的Google帐户的内容.
然而,当其他人想要登录并且我尝试"注销"该网站时,谷歌登录仍会记住它刚刚登录并且在注销后立即运行代码以再次登录.如果我从谷歌删除SSID cookie它没有这样做,所以我假设谷歌存储我刚刚用x登录的事实.
有没有办法当我退出时谷歌不能立即使用相同的帐户登录,而是要求谷歌用户的电子邮件和密码?
我觉得我在这里遗漏了一些明显的东西,但我无法弄清楚如何处理这个问题.
代码我用于Auth并获取数据:
<button class ="btn btn-primary" id="authorize-button" style="visibility: hidden">Log in</button>
<script>
var clientId = '';
var apiKey = '';
var scopes = '';
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
}
function checkAuth() {
//alert("authorize");
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
}
function handleAuthResult(authResult) {
//alert("authorized");
//alert(authResult.access_token);
var authorizeButton = document.getElementById('authorize-button');
if (authResult && !authResult.error) {
authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
var token = document.createElement('h4');
token.appendChild(document.createTextNode(authResult.access_token));
document.getElementById('content').appendChild(token);
}
function handleAuthClick(event) {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
return false;
}
var x;
function makeApiCall() {
//return;
gapi.client.load('plus', 'v1', function() {
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function(resp) {
x = resp.id;
var heading2 = document.createElement('h4');
var heading3 = document.createElement('h4');
heading3.appendChild(document.createTextNode(resp.displayName));
heading2.appendChild(document.createTextNode(resp.id));
document.getElementById('content2').appendChild(heading2);
document.getElementById('content3').appendChild(heading3);
$.post("token.php", {id: x});
});
});
}
Run Code Online (Sandbox Code Playgroud)
当您进行 auth 调用时,将approvalprompt 设置为force。这将强制每次都出现同意对话框。它会覆盖默认设置“自动”。您可以通过https://developers.google.com/+/web/signin/#sign-in_button_attributes了解更多信息。
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true, approvalprompt: force}
| 归档时间: |
|
| 查看次数: |
3160 次 |
| 最近记录: |