See if this past post will help: https://laracasts.com/discuss/channels/laravel/laravelsocialitetwoinvalidstateexception
Wouldn't hurt to have a look.
Hello, I have created a Laravel application and am trying to leverage the Google socialite authentication. I have defined the APP_URL and SESSION_DOMAIN configurations to each point to www.mywebsite.com and mywebsite.com respectively. In addition, the CLIENT_ID, CLIENT_SECRET and CLIENT_REDIRECT have also been configured. My GoogleAuthController class has two function (1) redirectToGoogle() and (2) handleGoogleCallback(Request $request). The web.xml routes have also been defined.
[A] What works: if I redirect to Google as follows: return Socialite::driver('google')->stateless()->setScopes(['openid', 'email'])->redirect(); and handle the callback as follows: $user = Socialite::driver('google')->stateless()->user();, authentication works but with limited user information (ex: no avatar and no name... just email).
[B] What doesn't work - and which I'm trying to solve:
(1) return Socialite::driver('google')->redirect(); (in redirectToGoogle())
(2)$user = Socialite::driver('google')->user(); (in handleGoogleCallback(Request $request))
The error that I get is: Laravel\Socialite\Two\InvalidStateException
I should note that both [A] and [B] work fine on my dev machine (localhost) but [B] fails on production (www.mysite.com).
I've spent a number of hours debugging this and am hitting a bit of a wall. Any thoughts would be much appreciated.
Server: Linux with php 8.1.4 (Laravel 9)
Please or to participate in this conversation.