1

我正在尝试访问使用 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_url401

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

4

0 回答 0