仅在首次加载角度网页时通过Safari接收401状态

use*_*827 5 safari mean node.js angularjs

问题

当使用Safari作为浏览器而不是Chrome浏览器时,加载Web应用程序首页时会收到401状态,这仅在该选项卡上首次出现,当我们打开新的选项卡并重新加载应用程序时,它加载正常。

我们使用的技术是MEAN堆栈,当我们使用Chrome / Firefox作为浏览器时,一切都很好(没有401错误,并且身份验证似乎很好),但是当我们切换到Safari时,它不起作用。

在React on SO上看到了类似的文章Safari接收401状态而不是Chrome,并确保端点具有正斜杠

API调用

get_change_lifecycle_data(){
    const params = new HttpParams().set('params', this.enteredValue);
    this.http.get('https://change-life-cycle.region02.hoster.company.com/api/change_life_cycle/',{params})
        .subscribe(response => {
        console.log("change data:");
         console.log(response);
         this.newPost = response
        //  this.splice_gerrits();
     });
}
Run Code Online (Sandbox Code Playgroud)

失败的请求:

Summary
URL: https://bati.company.com/runtime-es2015.858f8dd898b75fe86926.js
Status: 401 Unauthorized
Source: Network

Request
Origin: https://bati.company.com
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) companyWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15
Referer: https://bati.company.com/

Response
Content-Type: text/html
Date: Tue, 20 Aug 2019 00:02:58 GMT
Connection: keep-alive
Server: companyHttpServer/54b48526
Content-Length: 207
X-B3-TraceId: b39ab56a5e87f4f0
Strict-Transport-Security: max-age=31536000
Www-Authenticate: Basic realm="Enter your company OD credentials"
Run Code Online (Sandbox Code Playgroud)

打开新标签后成功请求:

Summary
URL: https://bati.company.com/runtime-es2015.858f8dd898b75fe86926.js
Status: 200 OK
Source: Memory Cache

Request
No request, served from the memory cache.

Response
ETag: "5d5b0e97-5a0"
Content-Type: application/x-javascript
Date: Tue, 20 Aug 2019 00:01:36 GMT
Last-Modified: Mon, 19 Aug 2019 21:03:19 GMT
Server: companyHttpServer/54b48526
Content-Length: 1440
Connection: keep-alive
Accept-Ranges: bytes
X-B3-TraceId: ecc642668834014e
Strict-Transport-Security: max-age=31536000
Run Code Online (Sandbox Code Playgroud)

更新:-

我可以通过发送curl请求来复制问题,我收到401错误响应

curl 'https://bati.company.com/runtime-es2015.858f8dd898b75fe86926.js' \
-XGET \
-H 'Origin: https://bait.company.com' \
-H 'Accept: */*' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) companyWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15' \
-H 'Referer: https://bait.company.com/'
Run Code Online (Sandbox Code Playgroud)

401错误响应

<html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>CompanyHttpServer/54b48526</center>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

UPDATE2:

curl -u username:password 'https://bati.company.com/runtime-es2015.858f8dd898b75fe86926.js' -XGET -H 'Origin: https://ibait.apple.com' -H 'Accept: */*' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15' -H 'Referer: https://ibait.apple.com/'
Run Code Online (Sandbox Code Playgroud)

UPDATE3:

api_change_foldscore_data(){
    const username = 'username'; // need to get these values from X-Forwarded-User
    const password = 'password';
    const headers = new HttpHeaders({
      Authorization: 'Basic ' + btoa(username + ':' + password)
    });
    this.http.get('https://change-life-cycle.hoster.company.com/api/change_fold_score', {headers, params})
        .subscribe(response => {
        console.log("change data:");
         console.log(response);
         this.newPost = response
     });
}
Run Code Online (Sandbox Code Playgroud)

小智 0

在后续请求(新选项卡)中,它由内存缓存提供。所以它似乎在缓存中,不确定它是如何到达那里的。您能否尝试清除 chrome 和 safari 中的所有缓存并刷新以查看新的 api 调用是否在两个浏览器中都具有所有必需的授权标头?