使用XHR请求从JS访问IAP安全资源?

时间:2019-10-19 10:14:37

标签: google-cloud-platform oauth-2.0 jwt google-iap

我正在尝试访问使用Google Cloud IAP(身份识别代理)保护的Google APP引擎。我可以使用邮递员以及身份标记来访问任何后端服务,例如(Node或Python)后端资源。但是,一旦我尝试使用相同的身份令牌从浏览器访问它,就会收到401未经授权的错误。

通过关注本文,我将获得身份令牌: 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);

错误消息: 选项my_url 401

从原点“ http://localhost:4200”到my_url的XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:无“ Access-Control-Allow-Origin”标头出现在请求的资源上

0 个答案:

没有答案