13
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Rails 4.x] Devise の Omniauth で Facebook 認証時に App Not Setup: などのエラーが出る場合

Last updated at Posted at 2014-11-05

前提

Linkedinの認証はうまくいくのにFacebook認証だけうまくいかなかったので、その時の対応策をメモします。

環境

個人環境: vagrant + centos65
開発環境: heroku
本番環境: heroku
Facebookアプリ作成アカウント: hoge@hoge.hoge

コード

config/initializers/devise.rb
  config.omniauth :facebook,
                  Rails.application.secrets.facebook_app_id,
                  Rails.application.secrets.facebook_app_secret

  config.secret_key = Rails.application.secrets.devise_secret_key
config/secrets.yml
development:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  devise_secret_key: <%= ENV["DEVISE_SECRET_KEY"] %>
  facebook_app_id: <%= ENV["FACEBOOK_APP_ID"] %>
  fecebook_app_secret: <%= ENV["FACEBOOK_APP_SECRET"] %>
~/.zshrc
export FACEBOOK_APP_ID="hoge"
export FACEBOOK_APP_SECRET="hogehoge"
export SECRET_KEY_BASE="fuga"
export DEVISE_SECRET_KEY="fuga"

エラー内容

ログ
Started GET "/users/auth/facebook"
INFO -- omniauth: (facebook) Request phase initiated.
INFO -- : Started GET "/users/auth/facebook/callback?code=mona&state=mona-"
INFO -- omniauth: (facebook) Callback phase initiated.
ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials: OAuth2::Error, :
{"error":{"message":"Error validating client secret.","type":"OAuthException","code":1}}
INFO -- : Processing by Users::OmniauthCallbacksController#failure as HTML
表示
ポップアップで
App Not Set Up: The developers of this app have not set it up properly for Facebook login
と表示される

めんどくさい点

このエラーは認証をするユーザーのFacebookアカウントが、Facebookアプリ作成アカウントと同じ場合は起きない。(2014/11/1時点)

対応

1. Facebookアプリを公開設定にする

とりあえず、Facebook Developerにログイン。
対応するアプリのページヘ。

  • Apps → Settings → Contact Email を入力
  • Apps → Status & Review → Do you want to make this app and all its live features available to the general public? → YES に変更。

Screen_Shot_2014-11-05_at_17_24_03.png

2. Privacy Policy URLなどを埋める

App Detailsでプライバシーポリシーが閲覧できるURLを設定します。
その周辺の欄も埋めておくといいのかも。

Screen_Shot_2014-11-05_at_17_26_25.png

ただ、この対応は必ずしも必要あるか不明。
Facebookアプリの管理画面でAlertが上がっているときだけ対応すればいいのかな?曖昧です。

3. Vagrantでは環境変数の参照をやめる

多分これが大きいのではないかと思われる。(私はこれで動作した)
config/secrets.ymlに直書きをする。
vagrant 環境以外では問題ないと思われる。

4. config/secrets.ymlを使わない。

よくあるマニュアルどおりに、config/initializers/devise.rbで対応。
vagrant だとここに直書きしないとうまくいかなかった。herokuでは動作した。(どうして?)

参考

13
11
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
13
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?