From bf19b1591400f70f190edcb1c3936ab969405d2d Mon Sep 17 00:00:00 2001 From: "David A. Cuadrado" Date: Sun, 31 Oct 2010 02:04:24 +0800 Subject: [PATCH] added open id support via omniauth --- Gemfile | 1 + Gemfile.lock | 19 +++++++++++-------- lib/devise/omniauth/url_helpers.rb | 4 ++-- test/omniauth/url_helpers_test.rb | 5 +++++ test/rails_app/config/initializers/devise.rb | 1 + 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 0dac1580..2c7033c4 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ gem "rails", "3.0.0" gem "webrat", "0.7.1" gem "mocha", :require => false gem "oa-oauth", :require => "omniauth/oauth" +gem "oa-openid", :require => "omniauth/openid" platforms :jruby do gem 'activerecord-jdbcsqlite3-adapter' diff --git a/Gemfile.lock b/Gemfile.lock index 1104fb46..b56c8680 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,7 +47,6 @@ GEM bson (1.0.4) bson_ext (1.0.7) builder (2.1.2) - columnize (0.3.1) erubis (2.6.6) abstract (>= 1.0.0) faraday (0.5.0) @@ -56,7 +55,6 @@ GEM rack (~> 1.2.1) i18n (0.4.1) jdbc-sqlite3 (3.6.3.054) - linecache (0.43) mail (2.2.6.1) activesupport (>= 2.3.6) mime-types @@ -85,6 +83,10 @@ GEM oa-core (= 0.1.4) oauth (~> 0.4.0) oauth2 (~> 0.0.10) + oa-openid (0.1.4) + oa-core (= 0.1.4) + rack-openid (~> 1.1.1) + ruby-openid-apps-discovery oauth (0.4.3) oauth2 (0.0.13) faraday (>= 0.4.1) @@ -94,6 +96,9 @@ GEM rack (1.2.1) rack-mount (0.6.13) rack (>= 1.0.0) + rack-openid (1.1.2) + rack (>= 0.4) + ruby-openid (>= 2.0.3) rack-test (0.5.5) rack (>= 1.0) rails (3.0.0) @@ -110,11 +115,9 @@ GEM rake (>= 0.8.4) thor (~> 0.14.0) rake (0.8.7) - ruby-debug (0.10.3) - columnize (>= 0.1) - ruby-debug-base (~> 0.10.3.0) - ruby-debug-base (0.10.3) - linecache (>= 0.3) + ruby-openid (2.1.8) + ruby-openid-apps-discovery (1.2.0) + ruby-openid (>= 2.1.7) sqlite3-ruby (1.3.1) thor (0.14.1) treetop (1.4.8) @@ -142,9 +145,9 @@ DEPENDENCIES mongo (= 1.0.7) mongoid (= 2.0.0.beta.18) oa-oauth + oa-openid orm_adapter (~> 0.0.2) rails (= 3.0.0) - ruby-debug (>= 0.10.3) sqlite3-ruby warden (~> 1.0.0) webrat (= 0.7.1) diff --git a/lib/devise/omniauth/url_helpers.rb b/lib/devise/omniauth/url_helpers.rb index cc7bc47f..7734ae34 100644 --- a/lib/devise/omniauth/url_helpers.rb +++ b/lib/devise/omniauth/url_helpers.rb @@ -5,9 +5,9 @@ module Devise return unless mapping.omniauthable? class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1 - def #{mapping.name}_omniauth_authorize_path(provider) + def #{mapping.name}_omniauth_authorize_path(provider, params = {}) if Devise.omniauth_configs[provider.to_sym] - "/#{mapping.path}/auth/\#{provider}" + "/#{mapping.path}/auth/\#{provider}?\#{params.to_param}" else raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}" end diff --git a/test/omniauth/url_helpers_test.rb b/test/omniauth/url_helpers_test.rb index 8a7996b7..c51d02ee 100644 --- a/test/omniauth/url_helpers_test.rb +++ b/test/omniauth/url_helpers_test.rb @@ -34,4 +34,9 @@ class OmniAuthRoutesTest < ActionController::TestCase @controller.omniauth_authorize_path(:user, :github) end 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") + end end diff --git a/test/rails_app/config/initializers/devise.rb b/test/rails_app/config/initializers/devise.rb index 0b0b549a..c1e402d8 100644 --- a/test/rails_app/config/initializers/devise.rb +++ b/test/rails_app/config/initializers/devise.rb @@ -150,6 +150,7 @@ Devise.setup do |config| # ==> OmniAuth config.omniauth :facebook, 'APP_ID', 'APP_SECRET', :scope => 'email,offline_access' + config.omniauth :open_id # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or