OAuth 2.0 and Phonegap's InAppBrowser for Authentication
OAuth 2.0 and Phonegap's InAppBrowser for Authentication
我正在尝试使用Oauth 2.0对登录其Google帐户的用户进行身份验证。为此,我需要访问他们的姓名和电子邮件地址。我正在使用Phonegap的InAppBrowser来做到这一点。
到目前为止,我有这个:
function openPage() {
var login_url = "https://accounts.google.com/o/oauth2/auth" + '?' + $.param({ client_id: "(not shown)", redirect_uri: "http://www.google.com", response_type: "token", scope: "openid profile email" });
var loginWindow = window.open(login_url, '_blank', 'location=yes');
loginWindow.addEventListener('loadstop', function(e) {
var url = e.url;
var access_token = url.split("access_token=")[1];
validateToken(access_token);
});
function validateToken(token) {
$.ajax({
url: 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' + token,
data: null,
success: function(responseText){
alert("Validation Success!");
getUserInfo(token);
},
dataType: "jsonp"
});
}
function getUserInfo(token) {
$.ajax({
url: 'https://www.googleapis.com/oauth2/v1/userinfo?access_token=' + token,
data: null,
success: function(resp) {
user = resp;
alert(JSON.stringify(user));
},
dataType: "jsonp"
});
}
}
令牌的验证每次都有效,但是一旦它调用getUserInfo(),返回的JSON就会充满错误和无效的凭据字符串。我做错了什么?谢谢!
我想您需要根据此处找到的用户信息端点的文档Authorization
标头中设置令牌
相关文章:
- 为什么JavaScript在for循环为3时向所有4发出警报
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- Is onfling available for html, html5
- Setting default onclick behavior for <img> tag in gene
- 我的javascript for循环不起作用
- For循环冻结Javascript
- 如何在for循环中添加事件侦听器
- Javascript setTimeout for an array
- 双“for”循环(循环)
- 引用vue.js中v-for中的上一个值
- javascript for循环不起作用
- for循环中的javascript if语句找不到==
- GWT (or javascript) library for couchDB
- Javascript在for循环中等待处理请求
- Livereload for node.js.有可能吗
- jQuery setTimeOut: in for-loop
- 我没有'I don’我不理解for在循环中的用途
- 如何知道javascript for语句中的所有结果是否都是错误的
- For循环在Jquery中只运行一次
- OAuth 2.0 and Phonegap's InAppBrowser for Authentication