【发布时间】:2014-09-04 00:37:39
【问题描述】:
我正在使用 Cordova 的 inappbrowser 并集成 Google oauth2.0。获得授权码后,我会发出一个发布请求以获取我的令牌。不管我尝试什么,我总是得到一个 400 错误“必需参数缺少 grant_type”。我正在编码 uri,我正在设置正确的标头但无济于事......有人可以帮忙吗?
$http({
method: 'POST',
url: 'https://accounts.google.com/o/oauth2/token',
params:{code:authorization_code[0],
client_id:options.client_id,
client_secret:options.client_secret,
redirect_uri:options.redirect_uri,
grant_type:'authorization_code'},
headers:{
'Content-Type':'application/x-www-form-urlencoded',
}
}).success(function(data,status,headers,config){
deferred.resolve(data);
}).error(function(data, status,headers,config){
console.log('data, status, headers,config',data,status,headers,config);
deferred.reject(response.responseJSON);
});
这是我尝试发出请求时 Chrome 开发控制台的输出
请求方法:POST
状态码:400 错误请求
请求标头
接受: application/json, text/plain, /
来源:file://
测试:测试
用户代理:Mozilla/5.0(Linux;Android 4.4.2;SCH-I535 Build/KOT49H)AppleWebKit/537.36(KHTML,如 Gecko)版本/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
查询字符串参数 client_id=xxx-oh7o4cmaju3jgprllln97nf0p3pc1f91.apps.googleusercontent.com&client_secret=xxx&code=4%2FnITDK731NhavPePthrVA1eX8LHFC.ojUX9K7DpBYaEnp6UAPFm0HWDS5njgI&grant_type=authorization_code&redirect_uri=http:%2F%2F
响应标头 HTTP/1.1 400 错误请求 Pragma:无缓存 日期:2014 年 7 月 14 日星期一 06:35:22 GMT 内容编码:gzip X-Content-Type-Options: nosniff 服务器:GSE X 框架选项:SAMEORIGIN 内容类型:应用程序/json 缓存控制:无缓存,无存储,最大年龄=0,必须重新验证 传输编码:分块 替代协议:443:quic X-XSS-防护:1;模式=块 过期:格林威治标准时间 1990 年 1 月 1 日星期五 00:00:00
【问题讨论】:
标签: angularjs google-oauth inappbrowser