To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 89 / 89e50c2e8b8d5c2174225ba4707520b699d0f276.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (1.77 KB)

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