LoginSignup
7
1

More than 3 years have passed since last update.

Rails5 devise twitterソーシャルログイン ローカル環境でのエラー解消

Posted at

ローカル環境でツイッターのソーシャルログインを試したい

以下を参考に実装。
[Rails] Facebook/Twitter/Googleでのユーザー登録をDevise & Omniauthを使って爆速で実装する

サインアップページでトリのボタンを押すとサインインページに遷移する謎

初回登録ページでトリを押すと。
image.png

ログインページに遷移する。
image.png

答えはコンソールに出力されていた。

web | I, [2020-01-29T16:56:34.815302 #7]  INFO -- omniauth: (twitter) Request phase initiated.
web | E, [2020-01-29T16:56:35.089161 #7] ERROR -- omniauth: (twitter) Authentication failure! service_unavailable: OpenSSL::SSL::SSLError, SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate in certificate chain)

SSL認証でエラーになっていた模様。当然だ。localhostだもの。

修正

こちらを参考に。OpenSSL::SSL::SSLError using Twitter #404

config/initailizers/devise.rb
  config.omniauth :twitter, ENV['TWITTER_APP_ID'], ENV['TWITTER_APP_SECRET']
  OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE if Rails.env.development?

Development環境のときだけ、 OpenSSL::SSL::VERIFY_NONEする。
無事、ツイッターログインできました。

7
1
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
7
1