ログインエラーが出ていたのを直した
Ruby 2.7.1にアップデートしたのでブログに書いておこうと思ってログインしたらエラーになった。
Herokuアプリのログを確認してみたところ:
2020-04-12T12:04:23.599633+00:00 app[web.1]: I, [2020-04-12T21:04:23.599545 #3] INFO -- : [14cc8621-cf83-41f0-bc6f-a6ce692ec238] Started POST "/auth/github?origin=https://oknm.jp/auth" for 175.131.16.228 at 2020-04-12 21:04:23 +0900
2020-04-12T12:04:23.600394+00:00 app[web.1]: I, [2020-04-12T21:04:23.600343 #3] INFO -- : [14cc8621-cf83-41f0-bc6f-a6ce692ec238] (github) Request phase initiated.
2020-04-12T12:04:23.604646+00:00 heroku[router]: at=info method=POST path="/auth/github?origin=https://oknm.jp/auth" host=oknm.jp request_id=14cc8621-cf83-41f0-bc6f-a6ce692ec238 fwd="175.131.16.228" dyno=web.1 connect=1ms service=8ms status=302 bytes=1307 protocol=http
2020-04-12T12:04:24.167130+00:00 heroku[router]: at=info method=GET path="/auth/github/callback?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch&state=adaf9f33d654c539841482c559e8b4b77c46a2f239aa5efa" host=oknm.jp request_id=58139b4d-7aa9-41b7-9037-6436dc4f6c24 fwd="175.131.16.228" dyno=web.1 connect=1ms service=8ms status=302 bytes=816 protocol=https
2020-04-12T12:04:24.162186+00:00 app[web.1]: I, [2020-04-12T21:04:24.162082 #3] INFO -- : [58139b4d-7aa9-41b7-9037-6436dc4f6c24] Started GET "/auth/github/callback?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch&state=adaf9f33d654c539841482c559e8b4b77c46a2f239aa5efa" for 175.131.16.228 at 2020-04-12 21:04:24 +0900
2020-04-12T12:04:24.163086+00:00 app[web.1]: I, [2020-04-12T21:04:24.163019 #3] INFO -- : [58139b4d-7aa9-41b7-9037-6436dc4f6c24] (github) Callback phase initiated.
2020-04-12T12:04:24.163635+00:00 app[web.1]: E, [2020-04-12T21:04:24.163560 #3] ERROR -- : [58139b4d-7aa9-41b7-9037-6436dc4f6c24] (github) Authentication failure! redirect_uri_mismatch: OmniAuth::Strategies::OAuth2::CallbackError, redirect_uri_mismatch | The redirect_uri MUST match the registered callback URL for this application. | https://developer.github.com/apps/managing-oauth-apps/troubleshooting-authorization-request-errors/#redirect-uri-mismatch
2020-04-12T12:04:24.364745+00:00 app[web.1]: I, [2020-04-12T21:04:24.364644 #3] INFO -- : [54454333-96e9-4f35-9fd3-606895a438f2] Started GET "/auth/failure?message=redirect_uri_mismatch&origin=https%3A%2F%2Foknm.jp%2Fauth&strategy=github" for 175.131.16.228 at 2020-04-12 21:04:24 +0900
redirect_uri_mismatch
とのこと。前まで動いてたのになぜ…。
いろいろ調べたところOmniAuth.config.full_host
を設定すればいいらしい?
参考: OmniAuth: ロードバランサ配下での redirect_uri_mismatch 問題 - tkrdの日記
とりあえず固定値で設定したところログインできるようになった。
https://github.com/okonomi/blg/commit/2b23ee190f8ff7c2be02654f8a390ad11b8a8ca2
なにかのgemのアップデートが影響してるのかな…