annotate .svn/pristine/1a/1ac4dbb6341375ce31f3dc814df9fd5800c3148d.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Mocks out OpenID
Chris@909 2 #
Chris@909 3 # http://www.northpub.com/articles/2007/04/02/testing-openid-support
Chris@909 4 module OpenIdAuthentication
Chris@909 5
Chris@909 6 EXTENSION_FIELDS = {'email' => 'user@somedomain.com',
Chris@909 7 'nickname' => 'cool_user',
Chris@909 8 'country' => 'US',
Chris@909 9 'postcode' => '12345',
Chris@909 10 'fullname' => 'Cool User',
Chris@909 11 'dob' => '1970-04-01',
Chris@909 12 'language' => 'en',
Chris@909 13 'timezone' => 'America/New_York'}
Chris@909 14
Chris@909 15 protected
Chris@909 16
Chris@909 17 def authenticate_with_open_id(identity_url = params[:openid_url], options = {}) #:doc:
Chris@909 18 if User.find_by_identity_url(identity_url) || identity_url.include?('good')
Chris@909 19 # Don't process registration fields unless it is requested.
Chris@909 20 unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?)
Chris@909 21 extension_response_fields = {}
Chris@909 22
Chris@909 23 options[:required].each do |field|
Chris@909 24 extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
Chris@909 25 end unless options[:required].nil?
Chris@909 26
Chris@909 27 options[:optional].each do |field|
Chris@909 28 extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
Chris@909 29 end unless options[:optional].nil?
Chris@909 30 end
Chris@909 31
Chris@909 32 yield Result[:successful], identity_url , extension_response_fields
Chris@909 33 else
Chris@909 34 logger.info "OpenID authentication failed: #{identity_url}"
Chris@909 35 yield Result[:failed], identity_url, nil
Chris@909 36 end
Chris@909 37 end
Chris@909 38
Chris@909 39 private
Chris@909 40
Chris@909 41 def add_simple_registration_fields(open_id_response, fields)
Chris@909 42 open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required]
Chris@909 43 open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional]
Chris@909 44 end
Chris@909 45 end