laravelheaderjwttokenhosting

Authorization header not reaching the server in laravel project


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?


Solution

  • Follow the second solution.

    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.

    file vendor\laravel\framework\src\Illuminate\Http\Concerns\InteractsWithInput.php method 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.