Cannot authenticate in Linkedin with angularjs / ionic. $http returns too fast

I am creating an app with Ionic / Cordova / AngularJS and I am using CordovaOauth to authenticate in my users in Linkedin.

The process fails at the last part, when asking for the access_token:

    var deferred = $q.defer();
// ...
    if((event.url).indexOf("http://localhost/callback") === 0) {
        requestToken = (event.url).split("code=")[1];
        $http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
        $http({method: "post", url: "https://www.linkedin.com/uas/oauth2/accessToken", data: "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=http://localhost/callback" + "&grant_type=authorization_code" + "&code=" + requestToken })
        .success(function(data) {
            deferred.resolve(data);
        })
        .error(function(data, status) {
            deferred.reject("Problem authenticating");
        })
        .finally(function() {
            setTimeout(function() {
                browserRef.close();
            }, 10);
        });
    }

In this part, the promise is always promptly rejected, BUT if I use it with Charles proxy, I can see that Linkedin actually responded with a working access_token. It seems that $http returns before getting the full response?

Thanks