Search code examples
angularjscordovaoauth-2.0google-oauthngcordova

Required parameter is missing: grant_type ngCordova/angular


I am using Google oAuth along with ngCordova. While I am able to retrieve access_token, the subsequent call to get refresh_token is failing. Here is my request. enter image description here

I have ensured that

  1. Content type is set.
  2. data is posted as form data and not in url as query string.

Here is the Javascript code

var clientSecret = encodeURI(result["access_token"]);
var req = {
    method: "POST",
    url:"https://accounts.google.com/o/oauth2/token",
    headers:{
            "Content-Type":"application/x-www-form-urlencoded"
           },
    data : {"code":clientSecret,"client_id":"XXXXX","client_secret":"XXX",
            "redirect_uri":"","grant_type":"authorization_code",scope:""}
};
$http(req).success(...).error(...);

Please someone tell me what I am doing wrong.


Solution

  • My Bad, the problem was with the authentication approach chosen by me. I was using ngCordova to invoke google authentication flow, which sets response_type to token. In my case, since I was expecting refresh token to be created once user authorizes app, the response_type was supposed to be set to code.

    I modified the code and it worked.