oa-oauth 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,5 +39,6 @@ module OmniAuth
39
39
  autoload :TradeMe, 'omniauth/strategies/trade_me'
40
40
  autoload :Teambox, 'omniauth/strategies/teambox'
41
41
  autoload :Tumblr, 'omniauth/strategies/tumblr'
42
+ autoload :Vkontakte, 'omniauth/strategies/vkontakte'
42
43
  end
43
44
  end
@@ -0,0 +1,84 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Vkontakte utilizing OAuth 2.0 and retrieve
8
+ # basic user information.
9
+ # documentation available here:
10
+ # http://vkontakte.ru/developers.php?o=-17680044&p=Authorization&s=0
11
+ #
12
+ # @example Basic Usage
13
+ # use OmniAuth::Strategies::Vkontakte, 'API Key', 'Secret Key'
14
+ class Vkontakte < OAuth2
15
+ # @param [Rack Application] app standard middleware application parameter
16
+ # @param [String] api_key the application id as [registered in Vkontakte]
17
+ # @param [String] secret_key the application secret as [registered in Vkontakte]
18
+ def initialize(app, api_key = nil, secret_key = nil, options = {}, &block)
19
+ client_options = {
20
+ :site => 'https://vkontakte.ru',
21
+ :authorize_url => 'http://api.vkontakte.ru/oauth/authorize',
22
+ :access_token_url => 'https://api.vkontakte.ru/oauth/token'
23
+ }
24
+
25
+ super(app, :vkontakte, api_key, secret_key, client_options, options, &block)
26
+ end
27
+
28
+ protected
29
+
30
+ def user_data
31
+ # http://vkontakte.ru/developers.php?o=-17680044&p=Description+of+Fields+of+the+fields+Parameter
32
+ @fields ||= ['uid', 'first_name', 'last_name', 'nickname', 'domain', 'sex', 'city', 'country', 'timezone', 'photo', 'photo_big']
33
+
34
+ # http://vkontakte.ru/developers.php?o=-1&p=getProfiles
35
+ @data ||= MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getProfiles?uid=#{@access_token['user_id']}&fields=#{@fields.join(',')}&access_token=#{@access_token.token}"))['response'][0]
36
+
37
+ # we need these 2 additional requests since vkontakte returns only ids of the City and Country
38
+ # http://vkontakte.ru/developers.php?o=-17680044&p=getCities
39
+ @city ||= MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getCities?cids=#{@data['city']}&access_token=#{@access_token.token}"))['response'][0]['name']
40
+
41
+ # http://vkontakte.ru/developers.php?o=-17680044&p=getCountries
42
+ @country ||= MultiJson.decode(@access_token.get("https://api.vkontakte.ru/method/getCountries?cids=#{@data['country']}&access_token=#{@access_token}"))['response'][0]['name']
43
+ end
44
+
45
+ def request_phase
46
+ options[:response_type] ||= 'code'
47
+ super
48
+ end
49
+
50
+ def user_info
51
+ {
52
+ 'firstname' => @data['first_name'],
53
+ 'last_name' => @data['last_name'],
54
+ 'name' => "#{@data['first_name']} #{@data['last_name']}",
55
+ 'nickname' => @data['nickname'],
56
+ 'image' => @data['photo'],
57
+ 'location' => "#{@country}, #{@city}",
58
+ 'urls' => {
59
+ 'Vkontakte' => "http://vkontakte.ru/#{@data['domain']}"
60
+ }
61
+ }
62
+ end
63
+
64
+ def user_hash
65
+ {
66
+ "user_hash" => {
67
+ "gender" => @data["sex"],
68
+ "timezone" => @data["timezone"],
69
+ "photo_big" => @data["photo_big"] # 200px maximum resolution of the avatar (http://vkontakte.ru/developers.php?o=-17680044&p=Description+of+Fields+of+the+fields+Parameter)
70
+ }
71
+ }
72
+ end
73
+
74
+ def auth_hash
75
+ user_data # process user's info
76
+ OmniAuth::Utils.deep_merge(super, {
77
+ 'uid' => @data['uid'],
78
+ 'user_info' => user_info,
79
+ 'extra' => user_hash
80
+ })
81
+ end
82
+ end
83
+ end
84
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: oa-oauth
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.2
5
+ version: 0.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Bleigh
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-16 00:00:00 -05:00
13
+ date: 2011-04-21 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.2.2
23
+ version: 0.2.3
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: *id001
@@ -29,9 +29,9 @@ dependencies:
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
- - - ~>
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.0.2
34
+ version: 0.0.5
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: *id002
@@ -80,8 +80,19 @@ dependencies:
80
80
  prerelease: false
81
81
  version_requirements: *id006
82
82
  - !ruby/object:Gem::Dependency
83
- name: rake
83
+ name: addressable
84
84
  requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - "="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: rake
95
+ requirement: &id008 !ruby/object:Gem::Requirement
85
96
  none: false
86
97
  requirements:
87
98
  - - ">="
@@ -89,10 +100,10 @@ dependencies:
89
100
  version: "0"
90
101
  type: :development
91
102
  prerelease: false
92
- version_requirements: *id007
103
+ version_requirements: *id008
93
104
  - !ruby/object:Gem::Dependency
94
105
  name: mg
95
- requirement: &id008 !ruby/object:Gem::Requirement
106
+ requirement: &id009 !ruby/object:Gem::Requirement
96
107
  none: false
97
108
  requirements:
98
109
  - - ~>
@@ -100,10 +111,10 @@ dependencies:
100
111
  version: 0.0.8
101
112
  type: :development
102
113
  prerelease: false
103
- version_requirements: *id008
114
+ version_requirements: *id009
104
115
  - !ruby/object:Gem::Dependency
105
116
  name: rspec
106
- requirement: &id009 !ruby/object:Gem::Requirement
117
+ requirement: &id010 !ruby/object:Gem::Requirement
107
118
  none: false
108
119
  requirements:
109
120
  - - ~>
@@ -111,10 +122,10 @@ dependencies:
111
122
  version: 1.3.0
112
123
  type: :development
113
124
  prerelease: false
114
- version_requirements: *id009
125
+ version_requirements: *id010
115
126
  - !ruby/object:Gem::Dependency
116
127
  name: webmock
117
- requirement: &id010 !ruby/object:Gem::Requirement
128
+ requirement: &id011 !ruby/object:Gem::Requirement
118
129
  none: false
119
130
  requirements:
120
131
  - - ~>
@@ -122,10 +133,10 @@ dependencies:
122
133
  version: 1.3.4
123
134
  type: :development
124
135
  prerelease: false
125
- version_requirements: *id010
136
+ version_requirements: *id011
126
137
  - !ruby/object:Gem::Dependency
127
138
  name: rack-test
128
- requirement: &id011 !ruby/object:Gem::Requirement
139
+ requirement: &id012 !ruby/object:Gem::Requirement
129
140
  none: false
130
141
  requirements:
131
142
  - - ~>
@@ -133,10 +144,10 @@ dependencies:
133
144
  version: 0.5.4
134
145
  type: :development
135
146
  prerelease: false
136
- version_requirements: *id011
147
+ version_requirements: *id012
137
148
  - !ruby/object:Gem::Dependency
138
149
  name: json_pure
139
- requirement: &id012 !ruby/object:Gem::Requirement
150
+ requirement: &id013 !ruby/object:Gem::Requirement
140
151
  none: false
141
152
  requirements:
142
153
  - - ~>
@@ -144,10 +155,10 @@ dependencies:
144
155
  version: 1.5.1
145
156
  type: :development
146
157
  prerelease: false
147
- version_requirements: *id012
158
+ version_requirements: *id013
148
159
  - !ruby/object:Gem::Dependency
149
160
  name: evernote
150
- requirement: &id013 !ruby/object:Gem::Requirement
161
+ requirement: &id014 !ruby/object:Gem::Requirement
151
162
  none: false
152
163
  requirements:
153
164
  - - ~>
@@ -155,7 +166,7 @@ dependencies:
155
166
  version: 0.9.0
156
167
  type: :development
157
168
  prerelease: false
158
- version_requirements: *id013
169
+ version_requirements: *id014
159
170
  description: OAuth strategies for OmniAuth.
160
171
  email: michael@intridea.com
161
172
  executables: []
@@ -200,6 +211,7 @@ files:
200
211
  - lib/omniauth/strategies/twitter.rb
201
212
  - lib/omniauth/strategies/type_pad.rb
202
213
  - lib/omniauth/strategies/vimeo.rb
214
+ - lib/omniauth/strategies/vkontakte.rb
203
215
  - lib/omniauth/strategies/xauth.rb
204
216
  - lib/omniauth/strategies/yahoo.rb
205
217
  - lib/omniauth/strategies/you_tube.rb
@@ -219,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
231
  requirements:
220
232
  - - ">="
221
233
  - !ruby/object:Gem::Version
222
- hash: -58406961140861733
234
+ hash: -2020535135575110083
223
235
  segments:
224
236
  - 0
225
237
  version: "0"
@@ -228,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
240
  requirements:
229
241
  - - ">="
230
242
  - !ruby/object:Gem::Version
231
- hash: -58406961140861733
243
+ hash: -2020535135575110083
232
244
  segments:
233
245
  - 0
234
246
  version: "0"