简体   繁体   English

Safari http 请求 header 没有反映 axios 拦截器的变化

[英]Safari http request header is not reflecting on axios interceptor's change

In my Vue + Laravel SPA application, when I change request header's Authorization from "Basic " to "Bearer", Chrome can send http request with "Bearer" header but in Safari still using "Basic " even though I changed Authorization in axios interceptors.在我的 Vue + Laravel SPA 应用程序中,当我将请求标头的授权从“Basic”更改为“Bearer”时,Chrome 可以发送带有“Bearer”header 的 http 请求,但在 Safari 中仍然使用“Basic”,即使我在 88269280884 中更改了授权

Why do they behave differently?为什么他们的行为不同? How can I fix it?我该如何解决? Any help tanks.任何帮助坦克。 * Details * 细节

.htaccess Basic Auth settings. .htaccess 基本身份验证设置。 All request needed Basic Auth credential but Jwt.所有请求都需要 Basic Auth 凭证,但 Jwt。

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Satisfy Any

AuthUserfile .htpasswd
AuthGroupfile /dev/null
AuthName "Enter your ID and PASSWORD"
AuthType Basic
require valid-user

SetEnvIf Authorization "(Bearer)" jwt_request
Order Deny,Allow
Deny from all
allow from env=jwt_request

<Files "service-worker.js">
   Require all granted
</Files>

axios settings for jwt axios 设置为 jwt

axios.interceptors.request.use(config => {
  config.headers['X-Requested-With'] = 'XMLHttpRequest'
  const token = store.getters['auth/token']
  if (token) {
    config.headers['Authorization'] = 'Bearer ' + token
  }
  return config
}

when I do console.log(config), it shows "Bearer + JWTtoken" but when I check Safari's.network console it uses "Basic " and it fails by jwt 401 with message "token is not provided".当我执行 console.log(config) 时,它显示“Bearer + JWTtoken”,但是当我检查 Safari 的 .network 控制台时,它使用“Basic”并且它失败了 jwt 401 并显示消息“未提供令牌”。

Safari(13.1)野生动物园(13.1)

Basic Auth and Bearer Auth use the same Authorization header. Chrome, Firefox, and Edge can authenticate with a username/password and pass a JWT. However, Safari 12+ will always override the Authorization header with the Basic Auth credentials. Basic Auth 和 Bearer Auth 使用相同的Authorization header。Chrome、Firefox 和 Edge 可以使用用户名/密码进行身份验证并传递 JWT。但是,Safari 12+ 将始终使用 Basic Auth 凭据覆盖Authorization header。

The solution to your issue is to use a custom header for authorization (eg. x-access-token ).您的问题的解决方案是使用自定义 header 进行授权(例如x-access-token )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM