Skip to content
This repository
Browse code

Delegate omniauth_authorize_path to the router, closes #1843

  • Loading branch information...
commit b1633f2454cd1f679ba82330ee2af6a70791fd09 1 parent 41a9118
José Valim josevalim authored
4 app/controllers/devise/omniauth_callbacks_controller.rb
... ... @@ -1,6 +1,10 @@
1 1 class Devise::OmniauthCallbacksController < DeviseController
2 2 prepend_before_filter { request.env["devise.skip_timeout"] = true }
3 3
  4 + def passthru
  5 + render :status => 404, :text => "Not found. Authentication passthru."
  6 + end
  7 +
4 8 def failure
5 9 set_flash_message :alert, :failure, :kind => failed_strategy.name.to_s.humanize, :reason => failure_message
6 10 redirect_to after_omniauth_failure_path_for(resource_name)
15 lib/devise/omniauth/url_helpers.rb
@@ -2,21 +2,6 @@ module Devise
2 2 module OmniAuth
3 3 module UrlHelpers
4 4 def self.define_helpers(mapping)
5   - return unless mapping.omniauthable?
6   -
7   - class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
8   - def #{mapping.name}_omniauth_authorize_path(provider, params = {})
9   - if Devise.omniauth_configs[provider.to_sym]
10   - script_name = request.env["SCRIPT_NAME"]
11   -
12   - path = "\#{script_name}/#{mapping.path}/auth/\#{provider}\".squeeze("/")
13   - path << '?' + params.to_param if params.present?
14   - path
15   - else
16   - raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}"
17   - end
18   - end
19   - URL_HELPERS
20 5 end
21 6
22 7 def omniauth_authorize_path(resource_or_scope, *args)
13 lib/devise/rails/routes.rb
@@ -396,8 +396,17 @@ def devise_omniauth_callback(mapping, controllers) #:nodoc:
396 396 path_prefix = Devise.omniauth_path_prefix || "/#{mapping.path}/auth".squeeze("/")
397 397 set_omniauth_path_prefix!(path_prefix)
398 398
399   - match "#{path_prefix}/:action/callback", :constraints => { :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) },
400   - :to => controllers[:omniauth_callbacks], :as => :omniauth_callback
  399 + providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s))
  400 +
  401 + match "#{path_prefix}/:provider",
  402 + :constraints => { :provider => providers },
  403 + :to => "#{controllers[:omniauth_callbacks]}#passthru",
  404 + :as => :omniauth_authorize
  405 +
  406 + match "#{path_prefix}/:action/callback",
  407 + :constraints => { :action => providers },
  408 + :to => controllers[:omniauth_callbacks],
  409 + :as => :omniauth_callback
401 410 ensure
402 411 @scope[:path] = path
403 412 end
9 test/omniauth/url_helpers_test.rb
@@ -30,7 +30,7 @@ def assert_path(action, provider, with_param=true)
30 30 test 'should generate authorization path' do
31 31 assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
32 32
33   - assert_raise ArgumentError do
  33 + assert_raise ActionController::RoutingError do
34 34 @controller.omniauth_authorize_path(:user, :github)
35 35 end
36 36 end
@@ -48,11 +48,4 @@ def assert_path(action, provider, with_param=true)
48 48 assert_equal "/users/auth/openid",
49 49 @controller.omniauth_authorize_path(:user, :openid)
50 50 end
51   -
52   - test 'should set script name in the path if present' do
53   - @request.env['SCRIPT_NAME'] = '/q'
54   -
55   - assert_equal "/q/users/auth/facebook",
56   - @controller.omniauth_authorize_path(:user, :facebook)
57   - end
58 51 end

0 comments on commit b1633f2

Please sign in to comment.
Something went wrong with that request. Please try again.