This article shows how to resolve CallbackError when GitHub authorizing at Heroku.
環境情報&前提条件
- Ruby 3.2.1
- Rails 7.0.0
- 開発環境
- Docker使用
- 本番環境
- Herokuにデプロイ(stack heroku-22)
gem
- devise 4.9.2
- omniauth 2.1.1
- omniauth-github 2.0.1
解決したい内容
- ローカルの開発環境でOmniauthによるGitHub認証ができることを確認済み。
- Heroku本番環境においてGitHub認証を実行すると、以下エラーが発生してGitHub認証に失敗する。
"OmniAuth::Strategies::OAuth2::CallbackError, redirect_uri_mismatch"
解決手順
-
config/initializers/devise.rb
に以下を追記する。https://hoge.herokuapp.com
の部分はご自身のアプリのURLに置換してください。
config/initializers/devise.rb
OmniAuth.config.full_host = 'https://hoge.herokuapp.com' if Rails.env.production?
参考記事
- 以下の記事を大いに参考にさせていただきました。