Merge pull request #1089 from skojin/master

support for named/dedicated openid
This commit is contained in:
José Valim 2011-05-24 13:33:32 -07:00
commit 03e3803cff
5 changed files with 18 additions and 1 deletions

View File

@ -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.

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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