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

danieletulone's avatar

Passport - State session value

Hi, I'm testing Passport. I'm using code from official doc and I have problem with the 'state' variable. My consumer app put the state on session. After redirect and login, in session there isn't state value, so the application return InvalidArgumentException.

Documentation Link: https://laravel.com/docs/master/passport#requesting-tokens

I'm using php 7.3.8 and I'm running two laravel applications with artisan serve.

0 likes
2 replies
fylzero's avatar

@danieletulone What session driver are you using in your env file? Try using cookie.

Maybe try defining state before using it at all.

$state = Str::random(40);
$request->session()->put('state', $state);

    $query = http_build_query([
        'client_id' => 'client-id',
        'redirect_uri' => 'http://example.com/callback',
        'response_type' => 'code',
        'scope' => '',
        'state' => $state,
    ]);
24 likes
danieletulone's avatar

Thanks but it doesn't work. In redirect I have the 'state' key with value in the url. The consumer application doesn't find 'state' from session.

1 like

Please or to participate in this conversation.