Skip to content

Commit

Permalink
Initial support for OpenID extensions.
Browse files Browse the repository at this point in the history
Extensions require implementation from ::OpenID::Extension
  • Loading branch information
scytrin committed Jun 28, 2008
1 parent d79bf8e commit a52cf1b
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions lib/rack/auth/openid.rb
Expand Up @@ -126,16 +126,15 @@ def initialize(realm, options={})
end

# TODO: extension support
if options.has_key? :extensions
warn "Extensions are not currently supported by Rack::Auth::OpenID"
end
ext = extensions(options).map{|ext,val| ext.to_s[/[^:]+$/].downcase }

@options = {
:session_key => 'rack.session',
:openid_param => 'openid_identifier',
#:return_to, :login_good, :login_fail, :login_quit
#:no_session, :auth_fail, :error
:store => OIDStore,
:extensions => ext,
:immediate => false,
:anonymous => false,
:catch_errors => false
Expand Down Expand Up @@ -214,6 +213,11 @@ def check(consumer, session, req)
query_args[2] = false if session.key? :setup_needed
pp query_args if $DEBUG

## Extension support
extensions.each do |ext,args|
oid.add_extension ext::Request.new(*args)
end

if oid.send_redirect?(*query_args)
redirect = oid.redirect_url(*query_args)
[ 303, {'Location'=>redirect}, [] ]
Expand Down Expand Up @@ -277,6 +281,13 @@ def finish(consumer, session, req)
body << "Authentication unsuccessful.\n"
when ::OpenID::Consumer::SUCCESS
session.clear

## Extension support
extensions.each do |ext,args|
label = ext.to_s[/[^:]+$/].downcase
session[label] = ext::Response.from_success_response(oid)
end

session['authenticated'] = true
# Value for unique identification and such
session['identity'] = oid.identity_url
Expand Down Expand Up @@ -305,6 +316,16 @@ def finish(consumer, session, req)
body << oid.message if oid.message
[ 303, {'Location'=>goto}, body]
end

private

def extensions from=@options
from.select do |e,v|
e.is_a? Module \
and ::OpenID::Extension > e::Request \
and ::OpenID::Extension > e::Response
end
end
end
end
end

0 comments on commit a52cf1b

Please sign in to comment.