I use Cordova inappbrowser and integrate Google oauth2.0. As soon as I get the authorization code, I make a mail request to get my token. The NO MATTER that I try always gets a 400 error with "Required Parameter is missing grant_type". I encode uri, I set the correct 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);
});
and this is the result of the Chrome dev console when trying to make a request

URL- : https://accounts.google.com/o/oauth2/token?client_id=736406995874-oh7o4cmaju3jgprllln97nf0p3pc1f91.apps.googleusercontent.com&client_secret=ysgrIV6mJXxritfXnRcclV_U&code=4%2FnITDK731NhavPePthrVA1eX8LHFC.ojUX9K7DpBYaEnp6UAPFm0HWDS5njgI&grant_type=authorization_code&redirect_uri=http:%2F%2Flocalhost
: POST
: 400 Bad Request
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, text/plain,/
: ://
:
User-Agent: Mozilla/5.0 (Linux; Android 4.4.2; SCH-I535 /KOT 49H) AppleWebKit/537,36 (KHTML, Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537,36
.
client_id = xxx-oh7o4cmaju3jgprllln97nf0p3pc1f91.apps.googleusercontent.com & client_secret = & = 4% 2FnITDK731NhavPePthrVA1eX8LHFC.ojUX9K7DpBYaEnp6UAPFm0HWDS5njgI & grant_type = authorization_code & redirect_uri = HTTP:% 2F% 2Flocalhost
HTTP/1.1 400
Pragma: no-cache
: , 14 2014 06:35:22 GMT
-: gzip
X-Content-Type: nosniff
: GSE
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Cache-Control: no-cache, no-store, max-age = 0, must-revalidate
-: chunked
: 443: quic
X-XSS-Protection: 1; =
: , 01 1990 00:00:00 GMT