I am trying to follow the Railscast 241 Simple OmniAuth and it works fine unless I have Route Globbing at the end of /config/routes.rb
:
match \
Slightly modified suggestion of Brandon Tilley:
# config/routes.rb
match '/auth/:provider/callback' => 'sessions#create'
match 'auth/*rest' => 'application#omniauth'
match '*uri' => 'posts#index'
# app/controllers/application_controller.rb
def omniauth
render text: 'Authentication', status: 404
end
The OmniAuth process is to provide the following functionality when a /auth/:provider
URL is called:
Since you are essentially matching everything using your route globbing, your application will never give 404's, and OmniAuth cannot do it's job. I see two immediate options.
Add a new route as follows:
match '/auth/:provider' => 'omniauth#passthru'
Then create a controller and action that generates a 404:
class OmniauthController < ApplicationController
def passthru
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
I assume that your glob route will search for a post matching the URL somehow; you can take misses (e.g. when PostsController#index
can't find a post) and generate 404's then.
class PostsController < ApplicationController
def index
if @posts = Post.find_by_current_url_or_whatever
render 'index'
else
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
end