InvalidStateException in line AbstractProvider.php 191 with courtesy

I get this error only on my local machine when I try to login using google or fb. I am almost 100% sure that my services and session.php are configured correctly. But alas, here we are ...

my services.php google settings:

'google' =>[ 'client_id'=> env('GOOGLE_CLIENT_ID'), 'client_secret' => env('GOOGLE_CLIENT_SECRET'), 'redirect' => "http://". env('DOMAIN'). "/login/google/callback", ], 

my session

 'domain'=> 'local.mysite.com' 
+6
source share
5 answers

I figured out the reason, and although I'm not sure why this problem occurs, it may be due to ubuntu / nginx versions, but here we go.

To get the right setup for laravel in nginx, I used this https://www.digitalocean.com/community/tutorials/how-to-install-laravel-with-an-nginx-web-server-on-ubuntu-14- 04

also confirmed by this https://laravel.com/docs/5.1/installation#pretty-urls

this is also the same nginx configuration as the estate, so, as a rule, there would not be any problem there, but after checking specifically for the query string when returning from google, I noticed that it was missing. The routes in laravel themselves worked fine, but he could not see the regular query lines.

so the answer is that inside the location block, not

try_files $uri $uri/ /index.php$query_string;

you need to use

try_files $uri $uri/ /index.php$is_args$args;

I found this from

Why is NGINX ignoring my query strings? (the most correct answer)

+4
source

The problem is with your sessions, which is always hard to understand. In oAuth2, you can provide the state parameter when sending the user for authentication, then it is sent back with the user to your application after authentication.

Socialite puts a random string in the session and this state parameter and checks that it contains the same value when the user returns.

See lines 134 and 212. https://github.com/laravel/socialite/blob/e04ab0bb972662fc72708dfd4eef35200965cca1/src/Two/AbstractProvider.php#L134

There are several solutions you can try ...

Firstly, you can only log in with your username and password instead of google oauth?

Verify that your config/session.php domain is set correctly and that the https parameter is set only to true if you are using HTTPS. If the https option is enabled, sessions will be established only when access to the site is through. Https

 'domain' => 'example.com', 

If you use subdomains in your application, add . to the beginning of your domain in the session configuration. This will allow the session to migrate to all subdomains.

 'domain' => '.example.com', 

When you go to your google account, you should see the state parameter in the URL, check this status, also returning when you return to your application.

You can also try clearing browser cookies and cache (or using an incognito window), which ensures that there are no conflicts between your previous tests / existing cookies.

You can also try reinstalling your dependencies by deleting the /vendor folder again and running composer install . This for me in the past solved problems with sessions for unknown reasons.

+3
source

A few options you could try:

  • Enter http:// into your session file for your domain as follows:

    'domain'=> 'http://local.mysite.com'

  • Make sure the domain and protocol are not different when executing the request and receiving the request.

  • Make sure your source address and the redirect address configured in your Google console match the routes configured in your application.

  • Run the following commands from the console. php artisan cache:clear and composer dump-autoload

  • Finally, clear your browsers cache and cookies.

0
source

If the same problem, none of the solutions worked, then I got the answer:

Check the .env file and make sure that SESSION_DRIVER is not set to the array

Array sessions will not be saved, so Socialite cannot check the status and return this error.

You can install:

 SESSION_DRIVER=file 

or select this type (except array): https://laravel.com/docs/5.0/session#session-drivers

If you use memcached / redis / database or a cookie, make sure they are configured and working.

0
source

I had the same error, and I decided that all social lines go to network middleware.

We need \ Illuminate \ Session \ Middleware \ StartSession to start the session.

0
source

All Articles