I've got a simple node.js backend build on Restify with OAuth2 authorization implemented (restify-oauth2 plugin).
I've got a problem requesting a token. When I call POST method with my REST client, everything works correctly and I get access_token
and token_type
.
The problem occurs when I try to do the same thing in my frontend aplication made in Angular using Restangular. It calls OPTIONS method before sending actual POST, and the server responds with an error:
XMLHttpRequest cannot load http://localhost:8080/token?grant_type=client_credentials.
Invalid HTTP status code 405
Here are my CORS settings on backend:
server.pre(
function crossOrigin(req,res,next){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
return next();
}
);
server.use(restify.fullResponse());
And this is REST call used in the frontend:
Restangular.one('token').post(
null,
null,
{grant_type: "client_credentials"},
{Authorization: "Basic bXlsb2dpbjpteXBhc3M="}
)
Can somebody help me figure out how to get it to work?