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

arnissolle's avatar

Retrieve the user id from session cookie

Hey,

I'd like to find the user id from the (string) session cookie (laravel_session). A third party person in the project is using my API, but only send the cookie laravel_session in the header to authenticate the user... I know it's not the best, but I cannot doing otherwise.

Many thanks!

0 likes
4 replies
martinbean's avatar

@arnissolle You can’t. The cookie is encrypted.

Use a more appropriate API authentication mechanism such as Passport if you need to give third parties access to your data.

arnissolle's avatar

I'd love to have the ability to do that, but I can't... really...

I mean, if Laravel can retrieve the user from the session token I could do it manually too!?...

The project have a web / login interface, and the mobile developer log the user through a webview, get the cookie "laravel_session" and then send me back via my API (same laravel project so, same encrypted key).

It's ugly, but I'm only the guy who does the maintenance...

arnissolle's avatar

I'd like to have something like this: Auth::viaSessionToken('my_laravel_session_token')->user()

I know it doesn't work, but I'd like something like this.

martinbean's avatar

The project have a web / login interface, and the mobile developer log the user through a webview, get the cookie "laravel_session" and then send me back via my API (same laravel project so, same encrypted key).

@arnissolle Christ. No, no, no.

Use Passport.

Please or to participate in this conversation.