I am trying to access Google APP engine which is secured using Google Cloud IAP(Identity Aware Proxy). I am able to access the resource using postman as well as any backend service like (Node or Python) by using the identity token. But as soon as I try to access it from browser using the same identity token, I get a 401 unauthorized error.
I am getting the identity token by following this article: https://engineering.q42.nl/google-identity-aware-proxy/
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "<appengine_url>", true);
xhr.setRequestHeader("Accept", "text/html,*/*");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("Authorization", "Bearer <identity_token>");
xhr.send(data);
Error message:
OPTIONS my_url
401
Access to XMLHttpRequest at my_url
from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource