前提・実現したいこと
Railsでwebアプリケーションを開発しています。
devise と omniauth-facebookのgemでfacebookアカウントでのログインを実装したいと考えております。
ローカルPCでのdevelopment環境ではうまくfacebook認証が動作するのですが、
AWSで立ち上げているstaging環境ではエラーが出てしまいます。
development環境では成功していることから、facebook for developersでの設定が間違っている可能性が高いと思っております。
設定で間違っている点がありますでしょうか??
発生している問題・エラーメッセージ
facebookログインボタン( <%= link_to "Facebookログイン", user_facebook_omniauth_authorize_path %>
)をクリックすると
facebookへとリダイレクトはされるのですが
(chromeのシークレットウィンドウで開いているためfacebookにログインする必要アリ↓)
ログインすると以下のエラーメッセージが表示されてしまいます。
確認する限りエラーに書かれている設定はクリアしているはずですが、何故か上手くいきません。
以上の動作から、
facebookへのリダイレクトまでは上手く行ってるが、facebookからのリダイレクトで失敗している認識です。
試したこと
(エラーメッセージにも書かれてますが)
以下の記事を見つけ、「有効なOAuthリダイレクトURI」欄にリダイレクトURLを完全一致させる必要があることは理解しました。
https://damelog.com/sns/facebook/facebook-login-redirect-url-becoming-strict-matching/
しかし、URLを完全一致で入力したはずにも関わらず、上記エラーが発生しています。
完全一致のURLはxxxxxxxxxxxxx/users/auth/facebook/callback である認識ですが、他にも可能性のあるURLも入力しています。
omniauth-facebookでのコード
↓user.rb
class User < ApplicationRecord ・ ・ ・ #omniauth-callback def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_create do |user| user.email = auth.info.email user.password = Devise.friendly_token[0,20] user.name = auth.info.name # assuming the user model has a name # user.picture = auth.info.image # assuming the user model has an image # If you are using confirmable and the provider(s) you use validate emails, # uncomment the line below to skip the confirmation emails. user.skip_confirmation! end end end
↓omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook # You need to implement the method below in your model (e.g. app/models/user.rb) @user = User.from_omniauth(request.env["omniauth.auth"]) if @user.persisted? sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format? else session["devise.facebook_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url end end def failure redirect_to root_path end end
補足情報(FW/ツールのバージョンなど)
ruby: 2.5.3
rails: 5.2.2
devise: 4.6.1
omniauth-facebook: 5.0.0
あなたの回答
tips
プレビュー