问题描述
我使用科尔多瓦的inappbrowser和整合谷歌的OAuth2.0。一旦我得到授权code我做一个post请求让我的令牌。不管我怎么努力,我总是得到一个400错误与缺少所需的参数grant_type。我编码URI,我设置了正确的头,但无济于事...谁能帮助?
I am using Cordova's inappbrowser and integrating Google oauth2.0. Once I get the authorization code I make a post request to get my token. NO MATTER what I try I always get a 400 error with "Required Parameter is missing grant_type". I'm encoding uri, I'm setting the right headers but to no avail... can anyone help?
$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开发者控制台输出的时候我尽量让请求
and this is the output from the Chrome dev Console when I try to make the request
请求URL:<一个href=\"https://accounts.google.com/o/oauth2/token?client_id=736406995874-oh7o4cmaju3jgprllln97nf0p3pc1f91.apps.googleusercontent.com&client_secret=ysgrIV6mJXxritfXnRcclV_U&$c$c=4%2FnITDK731NhavPePthrVA1eX8LHFC.ojUX9K7DpBYaEnp6UAPFm0HWDS5njgI&grant_type=authorization_$c$c&redirect_uri=http:%2F%2Flocalhost\" rel=\"nofollow\">https://accounts.google.com/o/oauth2/token?client_id=736406995874-oh7o4cmaju3jgprllln97nf0p3pc1f91.apps.googleusercontent.com&client_secret=ysgrIV6mJXxritfXnRcclV_U&$c$c=4%2FnITDK731NhavPePthrVA1eX8LHFC.ojUX9K7DpBYaEnp6UAPFm0HWDS5njgI&grant_type=authorization_$c$c&redirect_uri=http:%2F%2Flocalhost
请求方法:POST
状态code:400错误的请求
Status Code:400 Bad Request
请求头
发表 HTTP / 1.1
POST https://accounts.google.com/o/oauth2/token?client_id=xxx-oh7o4cmaju3jgprllln97nf0p3pc1f91.apps.googleusercontent.com&client_secret=xxx&code=4%2FnITDK731NhavPePthrVA1eX8LHFC.ojUX9K7DpBYaEnp6UAPFm0HWDS5njgI&grant_type=authorization_code&redirect_uri=http:%2F%2Flocalhost HTTP/1.1
接受应用程序/ JSON,纯文本/,的 / 的
Accept: application/json, text/plain, /
产地:文件://
测试:测试
的User-Agent:Mozilla的/ 5.0(Linux的,是Android 4.4.2,SCH-I535编译/ KOT49H)为AppleWebKit / 537.36(KHTML,例如Gecko)版本/ 4.0铬/ 30.0.0.0移动版Safari / 537.36
User-Agent: Mozilla/5.0 (Linux; Android 4.4.2; SCH-I535 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
查询字符串参数
client_id=xxx-oh7o4cmaju3jgprllln97nf0p3pc1f91.apps.googleusercontent.com&client_secret=xxx&$c$c=4%2FnITDK731NhavPePthrVA1eX8LHFC.ojUX9K7DpBYaEnp6UAPFm0HWDS5njgI&grant_type=authorization_$c$c&redirect_uri=http:%2F%2Flocalhost
Query String Parametersclient_id=xxx-oh7o4cmaju3jgprllln97nf0p3pc1f91.apps.googleusercontent.com&client_secret=xxx&code=4%2FnITDK731NhavPePthrVA1eX8LHFC.ojUX9K7DpBYaEnp6UAPFm0HWDS5njgI&grant_type=authorization_code&redirect_uri=http:%2F%2Flocalhost
响应头
HTTP / 1.1 400错误的请求
编译:无缓存
日期:星期一,2014年7月14日6点35分22秒GMT
内容编码:gzip
的X内容类型选项:nosniff
服务器:GSE
X框选项:SAMEORIGIN
内容类型:应用程序/ JSON
缓存控制:无缓存,无存储,最大年龄= 0,必重新验证
传输编码:分块
复用协议:443:QUIC
的X XSS-保护:1;模式=块
到期日:周五,1990年1月1日00:00:00 GMT
Response HeadersHTTP/1.1 400 Bad RequestPragma: no-cacheDate: Mon, 14 Jul 2014 06:35:22 GMTContent-Encoding: gzipX-Content-Type-Options: nosniffServer: GSEX-Frame-Options: SAMEORIGINContent-Type: application/jsonCache-Control: no-cache, no-store, max-age=0, must-revalidateTransfer-Encoding: chunkedAlternate-Protocol: 443:quicX-XSS-Protection: 1; mode=blockExpires: Fri, 01 Jan 1990 00:00:00 GMT
推荐答案
错误POST请求。在 PARAMS
属性用于设置附加到URL查询字符串的任何其他请求参数。在 PARAMS
属性是每个请求参数一个属性的JavaScript对象的补充。
Wrong post request. The params
property is used to set any additional request parameters to be appended to the URL query string. The params
property is a JavaScript object with one property per request parameter to add.
这篇关于缺少必需参数grant_type谷歌OAuth2.0的AngularJS和科尔多瓦inappbrowser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!