JWT 授权标头未到达 api [英] JWT Authorization header not reaching api

查看:17
本文介绍了JWT 授权标头未到达 api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的 laravel 项目部署在支持 mod_rewrite 的共享托管服务器上,并希望发送一个名为 Authorization 的标头(JWT 标头),但它不会到达控制器.

I deployed my laravel project on a shared hosting server that supports mod_rewrite and want to send a header called Authorization (JWT header) but it wont reach the controller.

mt .htaccess:

mt .htaccess:

选项 -MultiViews -Indexes重写引擎开启

Options -MultiViews -Indexes 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]

推荐答案

为了规避 Apache2 丢弃了我需要添加此代码的授权标头:

To evade Apache2 discards the authorization header I needed to add this code:

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

到我的/public 文件夹中的 .htcaccess 文件.

To my .htcaccess file in my /public folder.

这篇关于JWT 授权标头未到达 api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆