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

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

问题描述

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



mt .htaccess:



选项-MultiViews -Indexes

RewriteEngine On

 #句柄授权标题
RewriteCond%{HTTP:Authorization}。
RewriteRule。* - [E = HTTP_AUTHORIZATION:%{HTTP:Authorization}]

#重定向尾部斜线如果不是文件夹...
RewriteCond%{REQUEST_FILENAME}! - d
RewriteCond%{REQUEST_URI}(。+)/ $
RewriteRule ^%1 [L,R = 301]

#处理前端控制器...
RewriteCond%{REQUEST_FILENAME}!-d
RewriteCond%{REQUEST_FILENAME}!-f
RewriteRule ^ index.php [L]

解决方案

为了避免Apache2丢弃授权头,我需要添加以下代码:

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

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


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:

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]

解决方案

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

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

To my .htcaccess file in my /public folder.

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

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