[在我的Vue + Laravel SPA应用程序中,当我将请求标头的授权从“基本”更改为“承载”时,Chrome可以发送带有“承载”标头的http请求,但是即使我在axios中更改了授权,Chrome仍然使用Safari使用“基本”拦截器。
为什么他们的行为有所不同?我该如何解决?任何帮助坦克。*详细信息
。htaccess基本身份验证设置。所有请求都需要基本身份验证凭据,但需要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>
jwt的axios设置
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
}
[当我执行console.log(config)时,它显示“ Bearer + JWTtoken”,但是当我检查Safari的网络控制台时,它使用了“ Basic”,并且在jwt 401失败,并显示消息“ token not included”。
Safari(13.1)
基本身份验证和承载身份验证使用相同的Authorization
标头。 Chrome,Firefox和Edge可以使用用户名/密码进行身份验证并传递JWT。但是,Safari 12+始终会使用基本身份验证凭据覆盖Authorization
标头。