LoginSignup
1
1

More than 3 years have passed since last update.

AWSのELB(Elastic Load Balancing) 構成時に Auth0 認証の例外 (Invalid state) に対処する

Posted at

経緯

  1. ローカル環境 (ロードバランサー無し) ではうまく認証できる。
  2. AWS上 (ロードバランサーあり) だと Invalid state でエラーになる。

    /Auth0.php
    throw new CoreException('Invalid state');
    

    https://github.com/auth0/auth0-PHP/blob/660163b31beae4c550db68022c568b41df75d8e9/src/Auth0.php#L518

  3. エラーの原因を調べる。どうやら xxx.auth0.com 側の認証処理後に callback url に乗せて Get パラメータで戻される state の値とサーバの state の値に相違がある...。

結論

EC2 > ロードバランシング > ターゲットグループ > 属性の編集 > 「維持設定 有効化: on」 にする。

image.png

注: 根本解決ではないが、ひとまずこの対処でいくことにした。
一定負荷を超えた場合に備えてスケーラブルなサービスを提供している場合、この方法ではのちのち問題になるので Amazon ElastiCacheを使うのが定石らしい。

余談

んなことで2時間ちかく時間が...けどこれロードバランサー使うときの常識なんだろうな😂
ちゃんと理解しておかないと他のトラブル時に対処できない、まずいな。

参考

スティッキーセッションというらしい。
https://hack-le.com/sticky-session/

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1