36
37

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.

omniauth使っててログインキャンセルした時にトップにリダイレクトさせる

Posted at

そもそも僕の理解不足もあるんですけど、omniauthの実装例色々見てると
この部分無いの多い気がするんですがどうなんでしょう?
けっこうみんな普通に実装しちゃってるもんなんでしょうか?
確かにドキュメントにはちゃんと書いてあるんですが…

環境

  • ruby 1.9.3p392
  • Rails 3.2.11
  • ominiauth 1.1.3
  • omniauth-twitter 0.0.14
config/initializers/omniauth.rbに下記を追記
OmniAuth.config.on_failure = Proc.new { |env|
  OmniAuth::FailureEndpoint.new(env).redirect_to_failure
}
app/controllers/sessions_controller.rbにコールバック時のメソッド追加
  def failure
    redirect_to root_url, alert: "Authentication failed."
  end
config/routes.rbに追記
  match "/auth/failure" => "sessions#failure"

参考

https://github.com/intridea/omniauth/issues/616
https://github.com/intridea/omniauth/wiki/FAQ

36
37
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
36
37

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?