I can't find the solution for my problem. I'm trying to get google access token over OAuth 2.0 but I can't make my post method work. This is my code:
function oauthCallback(url) {
var code,
obj, request;
if (url.indexOf("code=") > 0) {
code = url.substr(url.indexOf('=') + 1);
request = $http({
method: "POST",
url: GOOGLE_TOKEN_URL,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: 'code=' + code + '&client_id=' + googleClientID + '&client_secret=' + googleClientSecret + '&redirect_uri=' + redirectURI + '&grant_type=authorization_code'
});
request.success( function(data) {
tokenStore['googleToken'] = data.access_token;
});
request.error( function(data, status, headers, config) {
alert('failed!')
});
deferredLogin.resolve();
} else if (url.indexOf("error=") > 0) {;
deferredLogin.reject(obj);
} else {
deferredLogin.reject({error: 'error occured', error_description: 'Unknown', error_reason: "Unknown"});
}
}
Using postman I've got access_token so the url and the data is correct. I've tried this and jsonp and many other answers but I always get the same result:
XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin
'http://localhost:63342'
is therefore not allowed access.
What am I doing wrong?