2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2012-01-03 23:36:40 +04:00
|
|
|
# Copyright (C) 2010-2012 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2009-02-11 22:07:18 +03:00
|
|
|
# Mocks out OpenID
|
|
|
|
#
|
|
|
|
# http://www.northpub.com/articles/2007/04/02/testing-openid-support
|
2011-05-30 22:52:25 +04:00
|
|
|
module OpenIdAuthentication
|
2009-02-11 22:07:18 +03:00
|
|
|
|
|
|
|
EXTENSION_FIELDS = {'email' => 'user@somedomain.com',
|
|
|
|
'nickname' => 'cool_user',
|
|
|
|
'country' => 'US',
|
|
|
|
'postcode' => '12345',
|
|
|
|
'fullname' => 'Cool User',
|
|
|
|
'dob' => '1970-04-01',
|
|
|
|
'language' => 'en',
|
2011-05-30 22:52:25 +04:00
|
|
|
'timezone' => 'America/New_York'}
|
2009-02-11 22:07:18 +03:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def authenticate_with_open_id(identity_url = params[:openid_url], options = {}) #:doc:
|
|
|
|
if User.find_by_identity_url(identity_url) || identity_url.include?('good')
|
|
|
|
# Don't process registration fields unless it is requested.
|
|
|
|
unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?)
|
|
|
|
extension_response_fields = {}
|
|
|
|
|
|
|
|
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-05-30 22:52:25 +04:00
|
|
|
logger.info "OpenID authentication failed: #{identity_url}"
|
2009-02-11 22:07:18 +03: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
|