Skip to content

Commit

Permalink
Added support for OpenID OAuth extension. This is still somewhat unte…
Browse files Browse the repository at this point in the history
  • Loading branch information
pelle committed Sep 26, 2009
1 parent 079b91f commit 909b75d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
* Added support for OpenID OAuth extension. [Pelle]

* Fake HTTP method from OpenID server since they only support a GET. Eliminates the need to set an extra route to match the server's reply. [Josh Peek]

* OpenID 2.0 recommends that forms should use the field name "openid_identifier" rather than "openid_url" [Josh Peek]
Expand Down
4 changes: 2 additions & 2 deletions init.rb
@@ -1,11 +1,11 @@
if config.respond_to?(:gems)
config.gem 'ruby-openid', :lib => 'openid', :version => '>=2.0.4'
config.gem 'pelle-ruby-openid', :lib => 'openid', :version => '>=2.1.8', :source => 'http://gems.github.com'
else
begin
require 'openid'
rescue LoadError
begin
gem 'ruby-openid', '>=2.0.4'
gem 'pelle-ruby-openid', '>=2.1.8', :lib => 'openid'
rescue Gem::LoadError
puts "Install the ruby-openid gem to enable OpenID support"
end
Expand Down
15 changes: 12 additions & 3 deletions lib/open_id_authentication.rb
Expand Up @@ -138,10 +138,12 @@ def begin_open_id_authentication(identity_url, options = {})

options[:required] ||= [] # reduces validation later
options[:optional] ||= []

open_id_request = open_id_consumer.begin(identity_url)
add_simple_registration_fields(open_id_request, options)
add_ax_fields(open_id_request, options)
add_oauth_fields(open_id_request, options )

redirect_to(open_id_redirect_url(open_id_request, return_to, method))
rescue OpenIdAuthentication::InvalidOpenId => e
yield Result[:invalid], identity_url, nil
Expand All @@ -160,8 +162,8 @@ def complete_open_id_authentication
when OpenID::Consumer::SUCCESS
profile_data = {}

# merge the SReg data and the AX data into a single hash of profile data
[ OpenID::SReg::Response, OpenID::AX::FetchResponse ].each do |data_response|
# merge the SReg data, the AX data and the OAuth data into a single hash of profile data
[ OpenID::SReg::Response, OpenID::AX::FetchResponse, OpenID::OAuth::FetchResponse ].each do |data_response|
if data_response.from_success_response( open_id_response )
profile_data.merge! data_response.from_success_response( open_id_response ).data
end
Expand Down Expand Up @@ -193,6 +195,13 @@ def add_simple_registration_fields(open_id_request, fields)
sreg_request.policy_url = fields[:policy_url] if fields[:policy_url]
open_id_request.add_extension(sreg_request)
end

def add_oauth_fields(open_id_request, options={})
return unless options[:oauth] && options[:oauth][:consumer]
oauth_request = OpenID::OAuth::Request.new options[:oauth][:consumer], options[:oauth][:scope]

open_id_request.add_extension(oauth_request)
end

def add_ax_fields( open_id_request, fields )
ax_request = OpenID::AX::FetchRequest.new
Expand Down

0 comments on commit 909b75d

Please sign in to comment.