Skip to content

Commit

Permalink
Errors now method calls rather than constants.
Browse files Browse the repository at this point in the history
darcs-hash:20071118044229-f4dbf-b7cd75eb9739fc75dabf6bd67f1502bfe59d0440.gz
  • Loading branch information
scytrin committed Nov 18, 2007
1 parent 0999973 commit a6cd992
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/rack/auth/openid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ module Auth
class OpenID < AbstractHandler
# Required for ruby-openid
OIDStore = ::OpenID::MemoryStore.new
# Basic error response, no session
E_NoSession = [500, {'Content-Type'=>'text/plain'}, 'Authentication method failed. No session found.']
# Basic error response, openid error
E_FailAuth = [401, {'Content-Type'=>'text/plain'}, 'Authentication failed.']

# A Hash of options is taken as it's single initializing argument. String
# keys are taken to be openid protocol extension namespaces. For example:
Expand Down Expand Up @@ -65,7 +61,7 @@ def call env
def check session, oid_url
consumer = ::OpenID::Consumer.new session, OIDStore
oid = consumer.begin oid_url
return E_FailAuth unless oid.status == ::OpenID::SUCCESS
return auth_fail unless oid.status == ::OpenID::SUCCESS
@options.each do |ns,s|
next unless String === ns
s.each {|k,v| oid.add_extension_arg(ns, k, v) }
Expand All @@ -78,14 +74,27 @@ def check session, oid_url
def finish session, params
consumer = ::OpenID::Consumer.new session, OIDStore
oid = consumer.complete params
return E_FailAuth unless oid.status == ::OpenID::SUCCESS
return bad_login unless oid.status == ::OpenID::SUCCESS
session[:openid] = {'identity' => oid.identity_url}
@options.each do |ns,s|
next unless String === ns
oid.extension_response(ns).each{|k,v| session[k]=v }
end
return [303, {'Location'=>@options[:trust]}, []]
end

def no_session
@options.
fetch :no_session, [500,{'Content-Type'=>'text/plain'},'No session available.']
end
def auth_fail
@options.
fetch :auth_fail, [500, {'Content-Type'=>'text/plain'},'Foreign server failure.']
end
def bad_login
@options.
fetch :bad_login, [401, {'Content-Type'=>'text/plain'},'Identification has failed.']
end
end
end
end

0 comments on commit a6cd992

Please sign in to comment.