2009-02-11 20:07:18 +01:00
|
|
|
# Mocks out OpenID
|
|
|
|
#
|
|
|
|
# http://www.northpub.com/articles/2007/04/02/testing-openid-support
|
2011-06-01 13:04:35 +02:00
|
|
|
module OpenIdAuthentication
|
2009-02-11 20:07:18 +01:00
|
|
|
|
2011-06-01 13:04:35 +02:00
|
|
|
EXTENSION_FIELDS = {'email' => 'user@somedomain.com',
|
2009-02-11 20:07:18 +01:00
|
|
|
'nickname' => 'cool_user',
|
2011-06-01 13:04:35 +02:00
|
|
|
'country' => 'US',
|
2009-02-11 20:07:18 +01:00
|
|
|
'postcode' => '12345',
|
|
|
|
'fullname' => 'Cool User',
|
2011-06-01 13:04:35 +02:00
|
|
|
'dob' => '1970-04-01',
|
2009-02-11 20:07:18 +01:00
|
|
|
'language' => 'en',
|
2011-06-01 13:04:35 +02:00
|
|
|
'timezone' => 'America/New_York'}
|
2009-02-11 20:07:18 +01:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
2018-06-08 02:55:41 +02:00
|
|
|
def authenticate_with_open_id(identity_url = params[:openid_url], options = {})
|
2009-02-11 20:07:18 +01:00
|
|
|
if User.find_by_identity_url(identity_url) || identity_url.include?('good')
|
2012-07-07 08:22:35 +02:00
|
|
|
extension_response_fields = {}
|
|
|
|
|
2009-02-11 20:07:18 +01:00
|
|
|
# Don't process registration fields unless it is requested.
|
|
|
|
unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?)
|
|
|
|
|
|
|
|
options[:required].each do |field|
|
|
|
|
extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
|
|
|
|
end unless options[:required].nil?
|
|
|
|
|
|
|
|
options[:optional].each do |field|
|
|
|
|
extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
|
|
|
|
end unless options[:optional].nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
yield Result[:successful], identity_url , extension_response_fields
|
|
|
|
else
|
2011-06-01 13:04:35 +02:00
|
|
|
logger.info "OpenID authentication failed: #{identity_url}"
|
2009-02-11 20:07:18 +01:00
|
|
|
yield Result[:failed], identity_url, nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def add_simple_registration_fields(open_id_response, fields)
|
|
|
|
open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required]
|
|
|
|
open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional]
|
|
|
|
end
|
|
|
|
end
|