mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
support for named omniauth open_id strategies
This commit is contained in:
parent
acd1c76c3b
commit
58f8c7c613
5 changed files with 18 additions and 1 deletions
|
@ -364,7 +364,8 @@ module Devise
|
|||
#
|
||||
def self.omniauth(provider, *args)
|
||||
@@helpers << Devise::OmniAuth::UrlHelpers
|
||||
@@omniauth_configs[provider] = Devise::OmniAuth::Config.new(provider, args)
|
||||
config = Devise::OmniAuth::Config.new(provider, args)
|
||||
@@omniauth_configs[config.strategy_name.to_sym] = config
|
||||
end
|
||||
|
||||
# Include helpers in the given scope to AC and AV.
|
||||
|
|
|
@ -10,6 +10,12 @@ module Devise
|
|||
@strategy = nil
|
||||
end
|
||||
|
||||
# open_id strategy can have configurable name
|
||||
def strategy_name
|
||||
options = @args.last.is_a?(Hash) && @args.last
|
||||
options && options[:name] ? options[:name] : @provider
|
||||
end
|
||||
|
||||
def strategy_class
|
||||
::OmniAuth::Strategies.const_get("#{::OmniAuth::Utils.camelize(@provider.to_s)}")
|
||||
end
|
||||
|
|
|
@ -35,6 +35,10 @@ class OmniAuthRoutesTest < ActionController::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'should generate authorization path for named open_id omniauth' do
|
||||
assert_match "/users/auth/google", @controller.omniauth_authorize_path(:user, :google)
|
||||
end
|
||||
|
||||
test 'should generate authorization path with params' do
|
||||
assert_match "/users/auth/open_id?openid_url=http%3A%2F%2Fyahoo.com",
|
||||
@controller.omniauth_authorize_path(:user, :open_id, :openid_url => "http://yahoo.com")
|
||||
|
|
|
@ -172,6 +172,7 @@ Devise.setup do |config|
|
|||
# ==> OmniAuth
|
||||
config.omniauth :facebook, 'APP_ID', 'APP_SECRET', :scope => 'email,offline_access'
|
||||
config.omniauth :open_id
|
||||
config.omniauth :open_id, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
|
||||
|
||||
# ==> Warden configuration
|
||||
# If you want to use other strategies, that are not supported by Devise, or
|
||||
|
|
|
@ -96,6 +96,11 @@ class DefaultRoutingTest < ActionController::TestCase
|
|||
assert_recognizes({:controller => 'users/omniauth_callbacks', :action => 'facebook'}, {:path => 'users/auth/facebook/callback', :method => :post})
|
||||
assert_named_route "/users/auth/facebook/callback", :user_omniauth_callback_path, :facebook
|
||||
|
||||
# named open_id
|
||||
assert_recognizes({:controller => 'users/omniauth_callbacks', :action => 'google'}, {:path => 'users/auth/google/callback', :method => :get})
|
||||
assert_recognizes({:controller => 'users/omniauth_callbacks', :action => 'google'}, {:path => 'users/auth/google/callback', :method => :post})
|
||||
assert_named_route "/users/auth/google/callback", :user_omniauth_callback_path, :google
|
||||
|
||||
assert_raise ActionController::RoutingError do
|
||||
assert_recognizes({:controller => 'ysers/omniauth_callbacks', :action => 'twitter'}, {:path => 'users/auth/twitter/callback', :method => :get})
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue