授权标头未到达 laravel 项目中的服务器 [英] Authorization header not reaching the server in laravel project

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

问题描述

我正在使用 JWT 令牌来授权 android 用户,但是当我将它发送为 null 时,服务器是否删除了 Authorization 标头?是否需要更改配置以允许我的标头传递到后端?

I'm using JWT token to authorize android users but when i send it it reaches as null, does the server remove the Authorization header? is there a config i need to change to allow my header to pass to the backend?

推荐答案

按照第二个解决方案.

我在 cPanel 托管中遇到了这个问题,一些安全模块或插件从标题中剥离了授权数据,我使用的是 Authorization Bearer.我通过重命名绕过它 Authorization ->ApiToken 并在 Laravel 核心中更新几行代码.

I faced this issue in cPanel hosting, some security mod or plugins strips the Authorization data from the header, I was using Authorization Bearer. I bypassed it by renaming Authorization -> ApiToken and updating few lines of code in Laravel core.

文件vendorlaravelframeworksrcIlluminateHttpConcernsInteractsWithInput.php方法bearerToken.

public function bearerToken()
{
    $header = $this->header('Authorization', $this->header('ApiToken', ''));

    if (Str::startsWith($header, 'Bearer ')) {
        return Str::substr($header, 7);
    }
}

顺便说一句,编辑核心代码并不理想.

Btw, editing core code is not ideal.

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

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