You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

open_id_authentication_mock.rb 1.8KB

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