「埋め込みブラウザのOAuthログイン」を有効にしてコールバックURLを指定した後でも、Facebookのコールバックエラーが発生する

prasad.surase

Facebookのログイン機能を使用するrails(4.2.0)アプリケーションがあります。主な宝石はdevise(3.4.0)とomniauth-facebook(2.0.0)です。Facebookにアプリケーションを登録し、そのテストアプリを開発に使用しています。Facebookのログイン機能は開発環境で機能します。

本番サーバーでFacebookログイン機能を使用しようとすると、「指定されたURLはアプリケーション構成で許可されていません:指定されたURLの1つ以上がアプリの設定で許可されていません。WebサイトのURLと一致する必要があります」というエラーが表示されます。キャンバスURL、またはドメインは、アプリのドメインの1つのサブドメインである必要があります。」

開発環境で使用されているテストアプリの設定詳細は次のとおりです-

Settings:
  Basic:
    App Domains: 'localhost'
    Website:
      Site URL: 'http://localhost:3000'
  Advanced:
    OAuth Settings:
      Embedded browser OAuth Login: Yes
      Valid OAuth redirect URIs: "http://localhost:3000/users/auth/facebook/callback"

本番環境で使用されている登録済みアプリの設定詳細は以下のとおりです。

Settings:
  Basic:
    App Domains: 'www.mysite.co'
    Website:
      Site URL: 'http://www.mysite.co'
  Advanced:
    OAuth Settings:
      Embedded browser OAuth Login: Yes
      Valid OAuth redirect URIs: "http://www.mysite.co/users/auth/facebook/callback"

私はsecrets.ymlで以下を指定しました

development:
  secret_key_base: some_secret_key 
  facebook:
    app_id: test_app_id
    app_secret: test_app_secret
production:
  secret_key_base: some_secret_key 
  facebook:
    app_id: registered_app_id
    app_secret: registered_app_secret

そして、デバイスのイニシャライザーでsecrets.ymlからのcredsを次のように使用しています

# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
require 'omniauth-facebook'
config.omniauth :facebook, Rails.application.secrets.facebook['app_id'], Rails.application.secrets.facebook['app_secret'], scope: ['user_photos', 'email', 'public_profile']

テストアプリの基本設定 テストアプリのコールバックURL アプリの基本設定 アプリのコールバックURL

実際のドメイン名(黒く塗りつぶされたもの)にはタイプミスがなく、どこで使用されても同じです。

omn​​iauthに関連するroutes.rbの内容は次のとおりです。

 cat config/routes.rb 
Rails.application.routes.draw do
  root 'home#index'

  devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }

  # routes related to other controllers
end

ルートは以下の通りです

bundle exec rake routes | grep user

new_user_session GET      /users/sign_in(.:format)                               devise/sessions#new
user_session POST     /users/sign_in(.:format)                               devise/sessions#create
destroy_user_session DELETE   /users/sign_out(.:format)                              devise/sessions#destroy
user_omniauth_authorize GET|POST /users/auth/:provider(.:format)                        users/omniauth_callbacks#passthru {:provider=>/facebook/}
user_omniauth_callback GET|POST /users/auth/:action/callback(.:format)                 users/omniauth_callbacks#:action

The only code related to omniauth in the entire app is as

$ cat app/controllers/users/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
end
prasad.surase

Upon further digging the problem, it was observed that the error didnt occur when 'www.example.com' was specified in the url and hence, the callback worked. When 'example.com' was specified in the address bar and facebook login tried, the login crashed with the above error.

So, I fixed the above issue by making some changes to the settings in for the facebook app. I donno if this is the right approach but it worked out. Just making the change as in point 2 didnt solve the problem.

Changes are:

1)「example.com」と「www.example.com」で「アプリドメイン」を指定しました。2)「はい」で「クライアントOAuthログイン」を有効にしました。3)「http:// example」で「有効なOAuthリダイレクトURI」を指定しました。.com / users / auth / facebook / callback 'および' http://www.example.com/users/auth/facebook/callback '

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

TOP 一覧

  1. 1

    Unity:未知のスクリプトをGameObject(カスタムエディター)に動的にアタッチする方法

  2. 2

    セレンのモデルダイアログからテキストを抽出するにはどうすればよいですか?

  3. 3

    Ansibleで複数行のシェルスクリプトを実行する方法

  4. 4

    tkinterウィンドウを閉じてもPythonプログラムが終了しない

  5. 5

    Crashlytics:コンパイラー生成とはどういう意味ですか?

  6. 6

    GoDaddyでのCKEditorとKCfinderの画像プレビュー

  7. 7

    Windows 10 Pro 1709を1803、1809、または1903に更新しますか?

  8. 8

    Chromeウェブアプリのウェブビューの高さの問題

  9. 9

    モーダルダイアログを自動的に閉じる-サーバーコードが完了したら、Googleスプレッドシートのダイアログを閉じます

  10. 10

    Windows 10の起動時間:以前は20秒でしたが、現在は6〜8倍になっています

  11. 11

    Reactでclsxを使用する方法

  12. 12

    ファイル内の2つのマーカー間のテキストを、別のファイルのテキストのセクションに置き換えるにはどうすればよいですか?

  13. 13

    MLでのデータ前処理の背後にある直感

  14. 14

    グラフからテーブルに条件付き書式を適用するにはどうすればよいですか?

  15. 15

    Pythonを使用して同じ列の同じ値の間の時差を取得する方法

  16. 16

    mutate_allとifelseを組み合わせるにはどうすればよいですか

  17. 17

    ネットワークグラフで、ネットワークコンポーネントにカーソルを合わせたときに、それらを強調表示するにはどうすればよいですか?

  18. 18

    テキストフィールドの値に基づいて UIslider を移動します

  19. 19

    BLOBストレージからデータを読み取り、Azure関数アプリを使用してデータにアクセスする方法

  20. 20

    PowerShellの分割ファイルへのヘッダーの追加

  21. 21

    ソートされた検索、ターゲット値未満の数をカウント

ホットタグ

アーカイブ