5 module OpenIdAuthentication
7 store = OpenIdAuthentication.store
9 Rails.logger.warn "OpenIdAuthentication.store is nil. Using in-memory store."
12 ::Rack::OpenID.new(app, OpenIdAuthentication.store)
19 def self.store=(*store_option)
20 store, *parameters = *([ store_option ].flatten)
24 require 'openid/store/memory'
25 OpenID::Store::Memory.new
27 require 'openid/store/filesystem'
28 OpenID::Store::Filesystem.new(Rails.root.join('tmp/openids'))
31 require 'openid/store/memcache'
32 OpenID::Store::Memcache.new(MemCache.new(parameters))
42 :missing => "Sorry, the OpenID server couldn't be found",
43 :invalid => "Sorry, but this does not appear to be a valid OpenID",
44 :canceled => "OpenID verification was canceled",
45 :failed => "OpenID verification failed",
46 :setup_needed => "OpenID verification needs setup"
61 ERROR_MESSAGES.keys.each { |state| define_method("#{state}?") { @code == state } }
68 ERROR_MESSAGES.keys.include?(@code)
77 # The parameter name of "openid_identifier" is used rather than
78 # the Rails convention "open_id_identifier" because that's what
79 # the specification dictates in order to get browser auto-complete
80 # working across sites
81 def using_open_id?(identifier = nil) #:doc:
82 identifier ||= open_id_identifier
83 !identifier.blank? || request.env[Rack::OpenID::RESPONSE]
86 def authenticate_with_open_id(identifier = nil, options = {}, &block) #:doc:
87 identifier ||= open_id_identifier
89 if request.env[Rack::OpenID::RESPONSE]
90 complete_open_id_authentication(&block)
92 begin_open_id_authentication(identifier, options, &block)
97 def open_id_identifier
98 params[:openid_identifier] || params[:openid_url]
101 def begin_open_id_authentication(identifier, options = {})
102 options[:identifier] = identifier
103 value = Rack::OpenID.build_header(options)
104 response.headers[Rack::OpenID::AUTHENTICATE_HEADER] = value
108 def complete_open_id_authentication
109 response = request.env[Rack::OpenID::RESPONSE]
110 identifier = response.display_identifier
113 when OpenID::Consumer::SUCCESS
114 yield Result[:successful], identifier,
115 OpenID::SReg::Response.from_success_response(response),
116 OpenID::AX::FetchResponse.from_success_response(response)
118 yield Result[:missing], identifier, nil
120 yield Result[:invalid], identifier, nil
121 when OpenID::Consumer::CANCEL
122 yield Result[:canceled], identifier, nil
123 when OpenID::Consumer::FAILURE
124 yield Result[:failed], identifier, nil
125 when OpenID::Consumer::SETUP_NEEDED
126 yield Result[:setup_needed], response.setup_url, nil