缺少必需参数grant_type谷歌OAuth2.0的AngularJS和科尔多瓦inappbrowser科尔、参数、多瓦、grant_type

2023-09-14 00:24:05 作者:壹聲姐妹大過天°

我使用科尔多瓦的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: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

请求头

发表 https://accounts.google.com/o/oauth2/token?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 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 Parameters 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 400错误的请求编译:无缓存日期:星期一,2014年7月14日6点35分22秒GMT内容编码:gzip的X内容类型选项:nosniff服务器:GSEX框选项:SAMEORIGIN内容类型:应用程序/ JSON缓存控制:无缓存,无存储,最大年龄= 0,必重新验证传输编码:分块复用协议:443:QUIC的X XSS-保护:1;模式=块到期日:周五,1990年1月1日00:00:00 GMT

Response Headers HTTP/1.1 400 Bad Request Pragma: no-cache Date: Mon, 14 Jul 2014 06:35:22 GMT Content-Encoding: gzip X-Content-Type-Options: nosniff Server: GSE X-Frame-Options: SAMEORIGIN Content-Type: application/json Cache-Control: no-cache, no-store, max-age=0, must-revalidate Transfer-Encoding: chunked Alternate-Protocol: 443:quic X-XSS-Protection: 1; mode=block Expires: 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.

这里供大家参考。