I need to implement Oauth2 identification in my polymer app, but i'm struggling with the iron-ajax. I want to provide the token through headers.
This is what I did:
<iron-ajax id="usersAjax"
auto
url="https://myawesomeurl.com/api/users"
method="GET"
handle-as="json"
headers="[[oauthToken]]"
last-response="{{usersList}}"></iron-ajax>
and the script:
oauthToken: {
type: "function",
value: function () {
var token = Cookies.get("Authorization");
var tokenString = {'Authorization': 'Bearer ' + token};
console.log("Oauth2 token: ", tokenString);
return tokenString;
}
}
ubt when I run it, it just fail. It cannot connect to the server because it expect a "GET" method, but it is automatically changed into "OPTION" according to the console:
OPTIONS https://myawesomeurl.com/api/users net::ERR_CONNECTION_REFUSED
In chrome dev tools > network, it says:
Provisional headers are shown Access-Control-Request-Headers:authorization Access-Control-Request-Method:GET Origin:http://localhost:8080 Referer:http://localhost:8080/admin-users User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Any ideas??