alex
alex

Reputation: 1900

Omniauth can't find route

I'm trying to implement Omniauth with my Rails 3 app. I followed the tutorial from the Railscast episod 205, but can't get it to work. When I call the '/auth/twitter' (it doesn't work with any provider) Rails complains it can't find the appropriate route (it tries to load my default route).

I added omniauth.rb under config/initializers/, put gem 'omniauth' in my Gemfile, and ran bundle install.

I'm not sure how to debug this problem nor what information to provide to help understand the problem.

Upvotes: 2

Views: 1446

Answers (3)

TravisP
TravisP

Reputation: 21

Here were my steps to get it working:

1) Add omniauth to your Gemfile

2) Add omniauth strategy to your Gemfile (omniauth-linkedin for example)

3) Run bundle install

4) Add the omniauth initializer in config/initializers/omniauth.rb

5) Add the match auth/:provider/callback => users#omniauth route to routes.rb (point it to the controller/action where you'll handle the authentication response)

6) Build the action to handle the authentication response in the controller you referenced in step #4

7) Restart your web server

The default /auth/:provider route wasn't recognized for me until I restarted Apache.

Upvotes: 1

GoVeM
GoVeM

Reputation: 5

You have to add 'omniauth-twitter' to your gemfile, and

:strategy_class => OmniAuth::Strategies::Twitter

to your omniauth.rb, at the end of the twitter provider.

Then it will recognize the /auth/twitter path.

Upvotes: 0

alex
alex

Reputation: 1900

After some research I found a solution. I added the following to my routes.rb file:

get 'auth/:provider' => 'authentications#passthru'

and to my authentications controller:

  def passthru
    render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
  end

Not sure why I had to do that, but it's working...

Upvotes: 1

Related Questions