oa-openid 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc ADDED
File without changes
data/LICENSE.rdoc ADDED
File without changes
data/README.rdoc ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ require 'omniauth/core'
2
+ require 'omniauth/strategies/open_id'
@@ -0,0 +1,7 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class Google < OmniAuth::Stratgies::OpenID
4
+ def identifier; 'https://www.google.com/accounts/o8/id' end
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,108 @@
1
+ require 'rack/openid'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class OpenID
6
+ include OmniAuth::Strategy
7
+
8
+ AX = {
9
+ :email => 'http://axschema.org/contact/email',
10
+ :name => 'http://axschema.org/namePerson',
11
+ :nickname => 'http://axschema.org/namePerson/friendly',
12
+ :first_name => 'http://axschema.org/namePerson/first',
13
+ :last_name => 'http://axschema.org/namePerson/last',
14
+ :city => 'http://axschema.org/contact/city/home',
15
+ :state => 'http://axschema.org/contact/state/home',
16
+ :website => 'http://axschema.org/contact/web/default',
17
+ :image => 'http://axschema.org/media/image/aspect11'
18
+ }
19
+
20
+ def initialize(app, store = nil, options = {})
21
+ super(app, options[:name] || :open_id)
22
+ @options = options
23
+ @options[:required] ||= [AX[:email], AX[:name], 'email', 'fullname']
24
+ @options[:optional] ||= [AX[:first_name], AX[:last_name], AX[:nickname], AX[:city], AX[:state], AX[:website], AX[:image], 'postcode', 'nickname']
25
+ @store = store
26
+ end
27
+
28
+ def dummy_app
29
+ lambda{|env| [401, {"WWW-Authenticate" => Rack::OpenID.build_header(
30
+ :identifier => identifier,
31
+ :return_to => callback_url,
32
+ :required => @options[:required],
33
+ :optional => @options[:optional]
34
+ )}, []]}
35
+ end
36
+
37
+ def callback_url
38
+ uri = URI.parse(request.url)
39
+ uri.path += '/callback'
40
+ uri.to_s
41
+ end
42
+
43
+ def identifier
44
+ request[:identifier]
45
+ end
46
+
47
+ def request_phase
48
+ return fail!(:missing_information) unless identifier
49
+ openid = Rack::OpenID.new(dummy_app, @store)
50
+ response = openid.call(env)
51
+ case env['rack.openid.response']
52
+ when Rack::OpenID::MissingResponse, Rack::OpenID::TimeoutResponse
53
+ fail :connection_failed
54
+ else
55
+ response
56
+ end
57
+ end
58
+
59
+ def callback_phase
60
+ openid = Rack::OpenID.new(lambda{|env| [200,{},[]]}, @store)
61
+ openid.call(env)
62
+ resp = env.delete('rack.openid.response')
63
+
64
+ case resp.status
65
+ when :failure
66
+ fail!(:invalid_credentials)
67
+ when :success
68
+ request['auth'] = auth_hash(resp)
69
+ @app.call(env)
70
+ end
71
+ end
72
+
73
+ def auth_hash(response)
74
+ OmniAuth::Utils.deep_merge(super(), {
75
+ 'uid' => response.display_identifier,
76
+ 'user_info' => user_info(response)
77
+ })
78
+ end
79
+
80
+ def user_info(response)
81
+ sreg_user_info(response).merge(ax_user_info(response))
82
+ end
83
+
84
+ def sreg_user_info(response)
85
+ sreg = ::OpenID::SReg::Response.from_success_response(response)
86
+ return {} unless sreg
87
+ {
88
+ 'email' => sreg['email'],
89
+ 'name' => sreg['fullname'],
90
+ 'location' => sreg['postcode'],
91
+ 'nickname' => sreg['nickname']
92
+ }.reject{|k,v| v.nil? || v == ''}
93
+ end
94
+
95
+ def ax_user_info(response)
96
+ ax = ::OpenID::AX::FetchResponse.from_success_response(response)
97
+ return {} unless ax
98
+ {
99
+ 'email' => ax[AX[:email]],
100
+ 'name' => ax[AX[:name]],
101
+ 'location' => ("#{ax[AX[:city]]}, #{ax[AX[:state]]}" if Array(ax[AX[:city]]).any? && Array(ax[AX[:state]]).any?),
102
+ 'nickname' => ax[AX[:nickname]],
103
+ 'urls' => ({'Website' => Array(ax[AX[:website]]).first} if Array(ax[AX[:website]]).any?)
104
+ }.inject({}){|h,(k,v)| h[k] = Array(v).first; h}.reject{|k,v| v.nil? || v == ''}
105
+ end
106
+ end
107
+ end
108
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oa-openid
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Michael Bleigh
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-29 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: oa-core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 0
31
+ version: 0.0.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rack-openid
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 1
55
+ - 2
56
+ - 9
57
+ version: 1.2.9
58
+ type: :development
59
+ version_requirements: *id003
60
+ - !ruby/object:Gem::Dependency
61
+ name: webmock
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :development
71
+ version_requirements: *id004
72
+ - !ruby/object:Gem::Dependency
73
+ name: rack-test
74
+ prerelease: false
75
+ requirement: &id005 !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ type: :development
83
+ version_requirements: *id005
84
+ - !ruby/object:Gem::Dependency
85
+ name: mg
86
+ prerelease: false
87
+ requirement: &id006 !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ type: :development
95
+ version_requirements: *id006
96
+ description: OpenID strategies for OmniAuth.
97
+ email: michael@intridea.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files: []
103
+
104
+ files:
105
+ - lib/omniauth/openid.rb
106
+ - lib/omniauth/strategies/google.rb
107
+ - lib/omniauth/strategies/open_id.rb
108
+ - README.rdoc
109
+ - LICENSE.rdoc
110
+ - CHANGELOG.rdoc
111
+ has_rdoc: true
112
+ homepage: http://github.com/intridea/omniauth
113
+ licenses: []
114
+
115
+ post_install_message:
116
+ rdoc_options: []
117
+
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.3.6
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: OpenID strategies for OmniAuth.
141
+ test_files: []
142
+