Skip to content
Browse files

Add OAuth Hybrid support

  • Loading branch information...
1 parent 06ec137 commit 3847a0c67e9140e902e2bbd6009683564dddd0ab @nov nov committed with josh Sep 8, 2010
Showing with 29 additions and 1 deletion.
  1. +1 −1 deps.rip
  2. +10 −0 lib/rack/openid.rb
  3. +18 −0 test/test_openid.rb
View
2 deps.rip
@@ -1,2 +1,2 @@
rack >=1.1.0
-ruby-openid >=2.0.3
+ruby-openid >=2.1.8
View
10 lib/rack/openid.rb
@@ -5,6 +5,7 @@
require 'openid/consumer'
require 'openid/extensions/sreg'
require 'openid/extensions/ax'
+require 'openid/extensions/oauth'
module Rack #:nodoc:
# A Rack middleware that provides a more HTTPish API around the
@@ -121,6 +122,7 @@ def begin_authentication(env, qs)
oidreq = consumer.begin(identifier)
add_simple_registration_fields(oidreq, params)
add_attribute_exchange_fields(oidreq, params)
+ add_oauth_fields(oidreq, params)
url = open_id_redirect_url(req, oidreq, params["trust_root"], params["return_to"], params["method"])
return redirect_to(url)
rescue ::OpenID::OpenIDError, Timeout::Error => e
@@ -244,6 +246,14 @@ def add_attribute_exchange_fields(oidreq, fields)
oidreq.add_extension(axreq)
end
+ def add_oauth_fields(oidreq, fields)
+ if (consumer = fields['oauth[consumer]']) &&
+ (scope = fields['oauth[scope]'])
+ oauthreq = ::OpenID::OAuth::Request.new(consumer, Array(scope).join(' '))
+ oidreq.add_extension(oauthreq)
+ end
+ end
+
def default_store
require 'openid/store/memory'
::OpenID::Store::Memory.new
View
18 test/test_openid.rb
@@ -232,6 +232,24 @@ def test_with_attribute_exchange
assert_equal 'success', @response.body
end
+ def test_with_oauth
+ @app = app(
+ :'oauth[consumer]' => 'www.example.com',
+ :'oauth[scope]' => ['http://docs.google.com/feeds/', 'http://spreadsheets.google.com/feeds/']
+ )
+ process('/', :method => 'GET')
+
+ location = @response.headers['Location']
+ assert_match(/openid.oauth.consumer/, location)
+ assert_match(/openid.oauth.scope/, location)
+
+ follow_redirect!
+ assert_equal 200, @response.status
+ assert_equal 'GET', @response.headers['X-Method']
+ assert_equal '/', @response.headers['X-Path']
+ assert_equal 'success', @response.body
+ end
+
def test_with_missing_id
@app = app(:identifier => "#{RotsServerUrl}/john.doe")
process('/', :method => 'GET')

0 comments on commit 3847a0c

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