如何撤销针对Google Api的身份验证令牌客户端 [英] How to revoke an authentication token client side against the Google Api
问题描述
我的代码如下所示:
$。get(https://accounts.google.com/o/oauth2/revoke?token=+ accessToken,function(){
window .location.reload();
});
我收到以下错误消息?
< blockquote>
XMLHttpRequest无法加载
https:/ /accounts.google.com/o/oauth2/revoke?token=tokenis此处 Origin
http:// balblabla。 com / 不允许通过Access-Control-Allow-Origin。
接下来来自@ krg的评论:
基于这个错误,它看起来像你不能在这个客户端上做到这一点。也许你需要一个服务器端脚本来处理你的域内的请求。您还可以浏览此解决方案。以下是使用该解决方案的 jsFiddle 示例。
我在服务器端使用了相同的代码:
lockquote
$。ajax({
url:https://accounts.google.com/o/oauth2/revoke?token=10100101,
dataType:'jsonp',//注意! JSONP< - P(小写)
成功:函数(json){
console.log(参数);
//用json做东西(在这种情况下是一个数组)
alert(Success);
},
error:function(){
alert(Error);
},
});
有效。
I am trying to revoke a token using the Google Api client side code.
My code looks something like this:
$.get("https://accounts.google.com/o/oauth2/revoke?token=" + accessToken, function () {
window.location.reload();
});
And I am getting the following error?
XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/revoke?token=tokenishere Origin http://balblabla.com is not allowed by Access-Control-Allow-Origin.
Following on from @krg's comment:
Based on the error it looks like you cannot do this on this client. Perhaps you'll need a server-side script to handle the request from within your domain. You can also explore this solution. Here's a jsFiddle example using the solution.
I have done this on the server side, using the same code:
$.ajax({ url:"https://accounts.google.com/o/oauth2/revoke?token=10100101", dataType: 'jsonp', // Notice! JSONP <-- P (lowercase) success:function(json){ console.log(arguments); // do stuff with json (in this case an array) alert("Success"); }, error:function(){ alert("Error"); }, });
which works.
这篇关于如何撤销针对Google Api的身份验证令牌客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!