Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lmartins's avatar

API endpoint returning 401 errors after upgrading to Laravel 5.7

Hi everyone,

I've been struggling to get around this problem that surfaced right after upgrading the framework to version 5.7.

I have this app in production, where part of the UI is driven by API requests. This has been working for more than a year, but since I've updated the framework the same requests now return {"error":"Unauthenticated."}.

I've checked the headers, and everything appears to be normal: https://cl.ly/69d469a314c5

Have anyone bumped into this problem too, how did you got around it?

0 likes
2 replies
D9705996's avatar

Make sure you update composer.json

laravel/passport: "^7.0",

The run composer update

lmartins's avatar

Thanks for the feedback @D9705996

I think I've figured out the problem, adding it here for anyone facing the same issue.

On the previous Laravel update, there were changes related to Cookies serialization.

As described at the documentation https://laravel.com/docs/5.6/upgrade, you could opt for serialize or not the cookies, passing the static property in the App\Http\Middleware\EncryptCookies middleware.

I did that, so I though the cookies were working like before.

That apparently isn't the case, because today the only way I could get this to work again was by following the instructions on that same link, running the Laravel\Passport\Passport::withoutCookieSerialization() method in the AppServiceProvider.

This method was supposed to be only necessary if cookie serialization was disabled, but for some reason that isn't happening for me.

Please or to participate in this conversation.