Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

SocialiteにおけるInvalidStateExceptionって

More than 3 years have passed since last update.

拙文より結論

  • 全部なにもかもセッションのせいだ
    • SESSION_DOMAINをちゃんと設定すれば良い

実装も間違ってないのに、ソーシャル先にもログインしてるのに何度やってもInvalidStateException

  • ソースコードを読むとどうもここっぽい
vendor/laravel/socialite/AbstractProvider.php
    /**
     * Determine if the current request / session has a mismatching "state".
     *
     * @return bool
     */
    protected function hasInvalidState()
    {
        if ($this->isStateless()) {
            return false;
        }

        $state = $this->request->session()->pull('state');

        return ! (strlen($state) > 0 && $this->request->input('state') === $state);
    }
  • セッションからstateっていうのをとってくるんだけど、それがnullでエラーになってるっぽい
  • .envに追加してやれば終わるという単純なお話でした
.env
SESSION_DOMAIN=hogehogefoo.com
  • こんな記事でも誰かの役に立てば幸いです
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away