the_social_login 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8cc11df2eacf2f1df99a97c2edf508014035c98
4
+ data.tar.gz: 34d8188ebf868980b0a3ab09ac485764d2aa4fd2
5
+ SHA512:
6
+ metadata.gz: 4cd1d2b5755e90f3e94328385fbb97ad82e19f88dc80f0b97a7d8ba9285ef04f1a7215962e3597860028e90a994e3762c3974a503aee23f4fec61ea153f0f42e
7
+ data.tar.gz: 219a0efd74b08d3c53bf8816975c7d14db9c6ae88ac9341d32aab9655d00703c9ef3b9290f054d724707605b3f04dc01a05037f12d7d476b46128e94219b4d8f
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in the_social_login.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ilya N. Zykin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # TheSocialLogin
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'the_social_login'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install the_social_login
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/the_social_login/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,229 @@
1
+ module SocialNetworksLogin
2
+ module Base
3
+ extend ActiveSupport::Concern
4
+
5
+ def self.networks_list
6
+ %w[ vkontakte facebook twitter google_oauth2 odnoklassniki ]
7
+ end
8
+
9
+
10
+ included do
11
+ attr_accessor :oauth_data
12
+
13
+ has_many :credentials, dependent: :destroy
14
+
15
+ before_validation :set_oauth_params, on: :create, if: ->{ oauth? }
16
+ before_validation :define_login, on: :create, if: ->{ oauth? }
17
+ before_validation :define_email, on: :create, if: ->{ oauth? }
18
+ before_validation :define_password, on: :create, if: ->{ oauth? }
19
+ before_save :skip_confirmation!, on: :create, if: ->{ oauth? }
20
+
21
+ after_save :create_credential, if: ->{ oauth? }
22
+ after_save :upload_oauth_avatar, if: ->{ oauth? }
23
+
24
+ def set_oauth_params
25
+ set_params_common_oauth
26
+ set_params_from_tw_oauth if twitter_oauth?
27
+ set_params_from_fb_oauth if facebook_oauth?
28
+ set_params_from_vk_oauth if vkontakte_oauth?
29
+ set_params_from_gp_oauth if google_oauth2_oauth?
30
+ set_params_from_ok_oauth if odnoklassniki_oauth?
31
+ end
32
+
33
+ def default_email_domain
34
+ 'my-web-site.com'
35
+ end
36
+
37
+ def attempts_to_generate
38
+ 10
39
+ end
40
+
41
+ # do something common here
42
+ def set_params_common_oauth
43
+ self.username = info.try(:[], 'name')
44
+ end
45
+
46
+ # do something special here
47
+ def set_params_from_gp_oauth
48
+ self.gp_addr = info.try(:[], 'urls').try(:[], 'Google')
49
+ end
50
+
51
+ def set_params_from_fb_oauth
52
+ self.fb_addr = info.try(:[], 'urls').try(:[], 'Facebook')
53
+ end
54
+
55
+ def set_params_from_vk_oauth
56
+ self.vk_addr = info.try(:[], 'urls').try(:[], 'Vkontakte')
57
+ end
58
+
59
+ def set_params_from_tw_oauth
60
+ self.tw_addr = info.try(:[], 'urls').try(:[], 'Twitter')
61
+ end
62
+
63
+ def set_params_from_ok_oauth
64
+ self.ok_addr = info.try(:[], 'urls').try(:[], 'Odnoklassniki')
65
+ end
66
+
67
+ def create_credential_with_oauth(uid, provider, _credentials)
68
+ exp_date = nil
69
+ exp_date = (Time.now + _credentials['expires_at'].to_i.seconds) if !_credentials['expires_at'].blank?
70
+
71
+ credentials_record = credentials.where(provider: provider).first
72
+
73
+ unless credentials_record
74
+ credentials_record = credentials.create(
75
+ uid: uid,
76
+ provider: provider,
77
+ expires_at: exp_date,
78
+ access_token: _credentials['token'],
79
+ access_token_secret: _credentials['secret'] # twitter
80
+ )
81
+
82
+ SystemMessage.create_credentials_for_user(self, provider)
83
+ end
84
+
85
+ credentials_record
86
+ end
87
+
88
+ def update_social_networks_urls! omniauth
89
+ info = omniauth.try(:[], 'info')
90
+
91
+ self.gp_addr = info.try(:[], 'urls').try(:[], 'Google') if self.gp_addr.blank?
92
+ self.fb_addr = info.try(:[], 'urls').try(:[], 'Facebook') if self.fb_addr.blank?
93
+ self.vk_addr = info.try(:[], 'urls').try(:[], 'Vkontakte') if self.vk_addr.blank?
94
+ self.tw_addr = info.try(:[], 'urls').try(:[], 'Twitter') if self.tw_addr.blank?
95
+ self.ok_addr = info.try(:[], 'urls').try(:[], 'Odnoklassniki') if self.ok_addr.blank?
96
+
97
+ self.save
98
+ end
99
+
100
+ private
101
+
102
+ # OAUTH helpers
103
+
104
+ def oauth?; !oauth_data.blank?; end
105
+
106
+ def oauth_params
107
+ @oauth_params ||= (begin; JSON.parse oauth_data; rescue; nil; end)
108
+ end
109
+
110
+ def info
111
+ @info ||= oauth_params.try(:[], 'info')
112
+ end
113
+
114
+ def extra
115
+ @extra ||= oauth_params.try(:[], 'extra')
116
+ end
117
+
118
+ def raw_info
119
+ @raw_info ||= oauth_params.try(:[], 'extra').try(:[], 'raw_info')
120
+ end
121
+
122
+ # base methods
123
+
124
+ SocialNetworksLogin::Base.networks_list.each do |network_name|
125
+ define_method "#{ network_name }_oauth?" do
126
+ oauth_params['provider'] == network_name
127
+ end
128
+ end
129
+
130
+ def create_credential
131
+ uid = oauth_params['uid']
132
+ provider = oauth_params['provider']
133
+ _credentials = oauth_params.try(:[], 'credentials')
134
+
135
+ create_credential_with_oauth(uid, provider, _credentials)
136
+ end
137
+
138
+ def define_login
139
+ # generate by oauth data
140
+ self.login = info.try(:[], 'nickname') if self.login.blank?
141
+ self.login = raw_info.try(:[], 'screen_name') if self.login.blank?
142
+
143
+ # generate by username with number
144
+ if self.login.blank? && self.username.present?
145
+ login_counter = 0
146
+ _login = self.username.to_slug_param
147
+
148
+ while User.find_by_login(_login) do
149
+ login_counter += 1
150
+ _login = [ self.username.to_slug_param, login_counter ].join ?-
151
+ _login = nil && break if login_counter == attempts_to_generate
152
+ end
153
+
154
+ self.login = _login
155
+ end
156
+
157
+ # generate by random value
158
+ if self.login.blank?
159
+ self.login = "user-#{ SecureRandom.hex[0..4] }"
160
+ end
161
+ end
162
+
163
+ def define_email
164
+ # generate by oauth data
165
+ self.email = info.try(:[], 'email') if self.email.blank?
166
+
167
+ # generate by login with number
168
+ if self.email.blank? && self.login.present?
169
+ email_counter = 0
170
+ _email = [ self.login, default_email_domain ].join ?@
171
+
172
+ while User.find_by_email(_email) do
173
+ email_counter += 1
174
+ _email = [ "#{ self.login }-#{ email_counter }", default_email_domain ].join ?@
175
+ _email = nil && break if email_counter == attempts_to_generate
176
+ end
177
+
178
+ self.email = _email
179
+ end
180
+
181
+ # generate by random value
182
+ if self.email.blank?
183
+ self.email = "#{ SecureRandom.hex[0..6] }@#{ default_email_domain }"
184
+ end
185
+ end
186
+
187
+ def define_password
188
+ self.password = SecureRandom.hex[0..10]
189
+ end
190
+
191
+ def upload_oauth_avatar
192
+ default_image = info.try(:[], 'image')
193
+ gp_avatar, fb_avatar, tw_avatar = Array.new(3, default_image)
194
+
195
+ vk_avatar = raw_info.try(:[], 'photo_200_orig')
196
+
197
+ if facebook_oauth?
198
+ json = JSON.parse(Net::HTTP.get(URI.parse(fb_avatar.gsub('&redirect=false', '') + '?type=large&redirect=false')))
199
+ unless json['data']['is_silhouette']
200
+ self.avatar = json['data']['url']
201
+ end
202
+ end
203
+
204
+ if twitter_oauth?
205
+ self.avatar = tw_avatar.gsub('_normal', '')
206
+ end
207
+
208
+ if vkontakte_oauth?
209
+ self.avatar = vk_avatar
210
+ end
211
+
212
+ if google_oauth2_oauth?
213
+ self.avatar = gp_avatar.gsub('s50', 's200').gsub('sz=50', 'sz=200')
214
+ end
215
+
216
+ if odnoklassniki_oauth?
217
+ self.avatar = raw_info.try(:[], 'pic_2')
218
+ end
219
+
220
+ reset_oauth_data!
221
+ save
222
+ end
223
+
224
+ def reset_oauth_data!
225
+ self.oauth_data, @oauth_params = [nil, nil]
226
+ end
227
+ end
228
+ end
229
+ end
data/gem_version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module TheSocialLogin
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'the_social_login/version'
2
+ _root_ = File.expand_path('../../', __FILE__)
3
+
4
+ module TheSocialLogin
5
+ class Engine < Rails::Engine; end
6
+ end
7
+
8
+ require "#{_root_}/app/models/concerns/social_networks_login_base"
@@ -0,0 +1 @@
1
+ require_relative '../../gem_version'
@@ -0,0 +1,472 @@
1
+ # SPEC EXAMPLE
2
+
3
+ ENV["RAILS_ENV"] ||= 'development'
4
+ require File.expand_path("../../../config/environment", __FILE__)
5
+
6
+ def create_user_without_oauth
7
+ puts "Without OAUTH"
8
+ user = User.create
9
+ puts user.errors.to_a
10
+ end
11
+
12
+ def create_user_with_facebook_oauth
13
+ # Facebook
14
+ json_data = '{
15
+ "provider":"facebook",
16
+ "uid":"100100100",
17
+ "info":{
18
+ "email":"killich@ya.ru",
19
+ "name":"Илья Зыкин",
20
+ "first_name":"Илья",
21
+ "last_name":"Зыкин",
22
+ "image":"http://graph.facebook.com/10202934219094389/picture&redirect=false",
23
+ "urls":{
24
+ "Facebook":"https://www.facebook.com/app_scoped_user_id/100100100/"
25
+ },
26
+ "verified":true
27
+ },
28
+ "credentials":{
29
+ "token":"my_tocken1000",
30
+ "expires_at":1405950180,
31
+ "expires":true
32
+ },
33
+ "extra":{
34
+ "raw_info":{
35
+ "id":"100100100",
36
+ "email":"killich@ya.ru",
37
+ "first_name":"Илья",
38
+ "gender":"male",
39
+ "last_name":"Зыкин",
40
+ "link":"https://www.facebook.com/app_scoped_user_id/100100100/",
41
+ "locale":"ru_RU",
42
+ "name":"Илья Зыкин",
43
+ "timezone":4,
44
+ "updated_time":"2014-05-22T12:14:08+0000",
45
+ "verified":true
46
+ }
47
+ }
48
+ }'
49
+
50
+ puts "With OAUTH"
51
+ user = User.create(oauth_data: json_data)
52
+ puts user.errors.to_a
53
+ end
54
+
55
+ def create_user_with_vk_oauth
56
+ # VKONTAKTE
57
+ json_data = '{
58
+ "provider":"vkontakte",
59
+ "uid":"100100100",
60
+ "info":{
61
+ "name":"Илья Николаевич",
62
+ "nickname":"",
63
+ "first_name":"Илья",
64
+ "last_name":"Николаевич",
65
+ "image":"http://cs304109.vk.me/v304109742/605e/mgMMsogBxLo.jpg",
66
+ "location":"Россия, Санкт-Петербург",
67
+ "urls":{
68
+ "Vkontakte":"http://vk.com/izzizzi"
69
+ }
70
+ },
71
+ "credentials":{
72
+ "token":"test_token",
73
+ "expires_at":1400935708,
74
+ "expires":true
75
+ },
76
+ "extra":{
77
+ "raw_info":{
78
+ "id":100100100,
79
+ "first_name":"Илья",
80
+ "last_name":"Николаевич",
81
+ "sex":2,
82
+ "nickname":"",
83
+ "screen_name":"izzizzi",
84
+ "bdate":"2.11.1984",
85
+ "city":2,
86
+ "country":1,
87
+ "photo_50":"http://cs304109.vk.me/v304109742/605e/mgMMsogBxLo.jpg",
88
+ "photo_100":"http://cs304109.vk.me/v304109742/605d/JNedY0oKESs.jpg",
89
+ "photo_200_orig":"http://cs304109.vk.me/v304109742/605b/AQrtEvxwZnM.jpg",
90
+ "online":1
91
+ }
92
+ }
93
+ }'
94
+
95
+ puts "With OAUTH"
96
+ user = User.create(oauth_data: json_data)
97
+ puts user.errors.to_a
98
+ end
99
+
100
+ def create_user_with_twitter_oauth
101
+ json_data = '{
102
+ "provider":"twitter",
103
+ "uid":"100100100",
104
+ "info":{
105
+ "nickname":"iam_teacher",
106
+ "name":"Илья Николаевич",
107
+ "location":"Питер",
108
+ "image":"http://pbs.twimg.com/profile_images/378800000801642062/07c6d6e7df7acc665af54172fb98494b_normal.jpeg",
109
+ "description":"Dreams on Rails",
110
+ "urls":{
111
+ "Website":"http://t.co/XE1VRDZXwr",
112
+ "Twitter":"https://twitter.com/iam_teacher"
113
+ }
114
+ },
115
+ "credentials":{
116
+ "token":"100100100-rHs4Yz9LPkhMEBXyeZxLWdfMZ6Qf30ySl40WaQs",
117
+ "secret":"e0UGMv4zsf2yit7TLpPoyZ0gHknWjtSn4u2jvkfDI12fW"
118
+ },
119
+ "extra":{
120
+ "access_token":{
121
+ "token":"100100100-rHs4Yz9LPkhMEBXyeZxLWdfMZ6Qf30ySl40WaQs",
122
+ "secret":"e0UGMv4zsf2yit7TLpPoyZ0gHknWjtSn4u2jvkfDI12fW",
123
+ "consumer":{
124
+ "key":"nOLguvZ6NFj142AUc4s1TZhby",
125
+ "secret":"ujWEH7rKF39EoTnJxzAHNx3dapaBzqQK67LDVd4ROP2AyaiYa8",
126
+ "options":{
127
+ "signature_method":"HMAC-SHA1",
128
+ "request_token_path":"/oauth/request_token",
129
+ "authorize_path":"/oauth/authenticate",
130
+ "access_token_path":"/oauth/access_token",
131
+ "proxy":null,
132
+ "scheme":"header",
133
+ "http_method":"post",
134
+ "oauth_version":"1.0",
135
+ "site":"https://api.twitter.com"
136
+ },
137
+ "http":{
138
+ "address":"api.twitter.com",
139
+ "port":443,
140
+ "local_host":null,
141
+ "local_port":null,
142
+ "curr_http_version":"1.1",
143
+ "keep_alive_timeout":2,
144
+ "last_communicated":null,
145
+ "close_on_empty_response":false,
146
+ "socket":null,
147
+ "started":false,
148
+ "open_timeout":30,
149
+ "read_timeout":30,
150
+ "continue_timeout":null,
151
+ "debug_output":null,
152
+ "proxy_from_env":true,
153
+ "proxy_uri":null,
154
+ "proxy_address":null,
155
+ "proxy_port":null,
156
+ "proxy_user":null,
157
+ "proxy_pass":null,
158
+ "use_ssl":true,
159
+ "ssl_context":{
160
+ "cert":null,
161
+ "key":null,
162
+ "client_ca":null,
163
+ "ca_file":null,
164
+ "ca_path":null,
165
+ "timeout":null,
166
+ "verify_mode":0,
167
+ "verify_depth":null,
168
+ "renegotiation_cb":null,
169
+ "verify_callback":null,
170
+ "options":-2147482625,
171
+ "cert_store":null,
172
+ "extra_chain_cert":null,
173
+ "client_cert_cb":null,
174
+ "tmp_dh_callback":null,
175
+ "session_id_context":null,
176
+ "session_get_cb":null,
177
+ "session_new_cb":null,
178
+ "session_remove_cb":null,
179
+ "servername_cb":null,
180
+ "npn_protocols":null,
181
+ "npn_select_cb":null
182
+ },
183
+ "ssl_session":{
184
+
185
+ },
186
+ "enable_post_connection_check":true,
187
+ "sspi_enabled":false,
188
+ "ca_file":null,
189
+ "ca_path":null,
190
+ "cert":null,
191
+ "cert_store":null,
192
+ "ciphers":null,
193
+ "key":null,
194
+ "ssl_timeout":null,
195
+ "ssl_version":null,
196
+ "verify_callback":null,
197
+ "verify_depth":null,
198
+ "verify_mode":0
199
+ },
200
+ "http_method":"post",
201
+ "uri":{
202
+ "scheme":"https",
203
+ "user":null,
204
+ "password":null,
205
+ "host":"api.twitter.com",
206
+ "port":443,
207
+ "path":"",
208
+ "query":null,
209
+ "opaque":null,
210
+ "registry":null,
211
+ "fragment":null,
212
+ "parser":null
213
+ }
214
+ },
215
+ "params":{
216
+ "oauth_token":"100100100-rHs4Yz9LPkhMEBXyeZxLWdfMZ6Qf30ySl40WaQs",
217
+ "oauth_token_secret":"e0UGMv4zsf2yit7TLpPoyZ0gHknWjtSn4u2jvkfDI12fW",
218
+ "user_id":"100100100",
219
+ "screen_name":"iam_teacher"
220
+ },
221
+ "response":{
222
+ "cache-control":[
223
+ "no-cache, no-store, must-revalidate, pre-check=0, post-check=0"
224
+ ],
225
+ "content-length":[
226
+ "653"
227
+ ],
228
+ "content-type":[
229
+ "application/json;charset=utf-8"
230
+ ],
231
+ "date":[
232
+ "Fri, 23 May 2014 12:56:48 GMT"
233
+ ],
234
+ "expires":[
235
+ "Tue, 31 Mar 1981 05:00:00 GMT"
236
+ ],
237
+ "last-modified":[
238
+ "Fri, 23 May 2014 12:56:48 GMT"
239
+ ],
240
+ "pragma":[
241
+ "no-cache"
242
+ ],
243
+ "server":[
244
+ "tfe"
245
+ ],
246
+ "set-cookie":[
247
+ "lang=ru",
248
+ "guest_id=v1%3A140084980831930062; Domain=.twitter.com; Path=/; Expires=Sun, 22-May-2016 12:56:48 UTC"
249
+ ],
250
+ "status":[
251
+ "200 OK"
252
+ ],
253
+ "strict-transport-security":[
254
+ "max-age=631138519"
255
+ ],
256
+ "x-access-level":[
257
+ "read"
258
+ ],
259
+ "x-content-type-options":[
260
+ "nosniff"
261
+ ],
262
+ "x-frame-options":[
263
+ "SAMEORIGIN"
264
+ ],
265
+ "x-rate-limit-limit":[
266
+ "15"
267
+ ],
268
+ "x-rate-limit-remaining":[
269
+ "14"
270
+ ],
271
+ "x-rate-limit-reset":[
272
+ "1400850708"
273
+ ],
274
+ "x-transaction":[
275
+ "b072b432de4625c6"
276
+ ],
277
+ "x-xss-protection":[
278
+ "1; mode=block"
279
+ ],
280
+ "connection":[
281
+ "close"
282
+ ]
283
+ }
284
+ },
285
+ "raw_info":{
286
+ "id":100100100,
287
+ "id_str":"100100100",
288
+ "name":"Илья Николаевич",
289
+ "screen_name":"iam_teacher",
290
+ "location":"Питер",
291
+ "description":"Dreams on Rails",
292
+ "url":"http://t.co/XE1VRDZXwr",
293
+ "entities":{
294
+ "url":{
295
+ "urls":[
296
+ {
297
+ "url":"http://t.co/XE1VRDZXwr",
298
+ "expanded_url":"http://open-cook.ru",
299
+ "display_url":"open-cook.ru",
300
+ "indices":[
301
+ 0,
302
+ 22
303
+ ]
304
+ }
305
+ ]
306
+ },
307
+ "description":{
308
+ "urls":[
309
+
310
+ ]
311
+ }
312
+ },
313
+ "protected":false,
314
+ "followers_count":17,
315
+ "friends_count":43,
316
+ "listed_count":0,
317
+ "created_at":"Sat Sep 21 19:26:54 +0000 2013",
318
+ "favourites_count":1,
319
+ "utc_offset":null,
320
+ "time_zone":null,
321
+ "geo_enabled":false,
322
+ "verified":false,
323
+ "statuses_count":45,
324
+ "lang":"ru",
325
+ "contributors_enabled":false,
326
+ "is_translator":false,
327
+ "is_translation_enabled":false,
328
+ "profile_background_color":"C0DEED",
329
+ "profile_background_image_url":"http://abs.twimg.com/images/themes/theme1/bg.png",
330
+ "profile_background_image_url_https":"https://abs.twimg.com/images/themes/theme1/bg.png",
331
+ "profile_background_tile":false,
332
+ "profile_image_url":"http://pbs.twimg.com/profile_images/378800000801642062/07c6d6e7df7acc665af54172fb98494b_normal.jpeg",
333
+ "profile_image_url_https":"https://pbs.twimg.com/profile_images/378800000801642062/07c6d6e7df7acc665af54172fb98494b_normal.jpeg",
334
+ "profile_link_color":"0084B4",
335
+ "profile_sidebar_border_color":"C0DEED",
336
+ "profile_sidebar_fill_color":"DDEEF6",
337
+ "profile_text_color":"333333",
338
+ "profile_use_background_image":true,
339
+ "default_profile":true,
340
+ "default_profile_image":false,
341
+ "following":false,
342
+ "follow_request_sent":false,
343
+ "notifications":false
344
+ }
345
+ }
346
+ }'
347
+
348
+ puts "With OAUTH"
349
+ user = User.create(oauth_data: json_data)
350
+ puts user.errors.to_a
351
+ end
352
+
353
+ def create_user_with_google_oauth
354
+ json_data = '{
355
+ "provider":"google_oauth2",
356
+ "uid":"100100100",
357
+ "info":{
358
+ "name":"Илья Николаевич",
359
+ "email":"gkillich@gmail.com",
360
+ "first_name":"Илья",
361
+ "last_name":"Николаевич",
362
+ "image":"https://lh6.googleusercontent.com/-_4nOVdM7f7U/AAAAAAAAAAI/AAAAAAAAAEE/ju9NEnysXHw/s50/photo.jpg?sz=50",
363
+ "urls":{
364
+ "Google":"https://plus.google.com/100100100"
365
+ }
366
+ },
367
+ "credentials":{
368
+ "token":"token",
369
+ "expires_at":1400854629,
370
+ "expires":true
371
+ },
372
+ "extra":{
373
+ "id_token":"tken--J0kytfs",
374
+ "raw_info":{
375
+ "kind":"plus#personOpenIdConnect",
376
+ "gender":"male",
377
+ "sub":"100100100",
378
+ "name":"Илья Николаевич",
379
+ "given_name":"Илья",
380
+ "family_name":"Николаевич",
381
+ "profile":"https://plus.google.com/100100100",
382
+ "picture":"https:https://lh6.googleusercontent.com/-_4nOVdM7f7U/AAAAAAAAAAI/AAAAAAAAAEE/ju9NEnysXHw/photo.jpg?sz=50",
383
+ "email":"gkillich@gmail.com",
384
+ "email_verified":"true",
385
+ "locale":"ru"
386
+ }
387
+ }
388
+ }'
389
+
390
+ puts "With OAUTH"
391
+ user = User.create(oauth_data: json_data)
392
+ puts user.errors.to_a
393
+ end
394
+
395
+ def create_user_with_ok_oauth
396
+ json_data = {
397
+ "provider" => "odnoklassniki",
398
+ "uid" => "100100100",
399
+ "info" =>
400
+ {
401
+ "name" => "Илья Николаевич",
402
+ "first_name" => "Илья",
403
+ "last_name" => "Николаевич",
404
+ "image" => "http://i500.mycdn.me/getImage?photoId=575482180985&photoType=4&viewToken=0o2ycgAO8MnOCYN6vg9leg",
405
+ "urls" => {
406
+ "Odnoklassniki" => "http://www.odnoklassniki.ru/profile/100100100"
407
+ }
408
+ },
409
+ "credentials" => {
410
+ "token" => "bvipa.628k1rpp3k3bsr9asda3df",
411
+ "refresh_token" => "a914766d0d3985eec",
412
+ "expires_at" => 1410968541,
413
+ "expires" => true
414
+ },
415
+ "extra" => {
416
+ "raw_info" => {
417
+ "uid" => "100100100",
418
+ "birthday" => "1984-11-02",
419
+ "age" => 29,
420
+
421
+ "first_name" => "Илья",
422
+ "last_name" => "Николаевич",
423
+ "name" => "Илья Николаевич",
424
+
425
+ "locale" => "ru",
426
+ "gender" => "male",
427
+ "has_email" => true,
428
+ "location" => {
429
+ "city" => "Санкт-Петербург",
430
+ "country" => "RUSSIAN_FEDERATION",
431
+ "countryCode" => "RU",
432
+ "countryName" => "Россия"
433
+ },
434
+
435
+ "current_status" => "Православный Невский )))",
436
+ "current_status_id" => "6206253",
437
+ "current_status_date" => "2014-09-12 12:05:10",
438
+ "online" => "web",
439
+ "photo_id" => "575482180985",
440
+ "pic_1" => "http://i500.mycdn.me/getImage?photoId=575482180985&photoType=4&viewToken=0o2ycgAO8MnOCYN6vg9leg",
441
+ "pic_2" => "http://usd1.mycdn.me/getImage?photoId=575482180985&photoType=2&viewToken=0o2ycgAO8MnOCYN6vg9leg"
442
+ }
443
+ }
444
+ }.to_json
445
+
446
+ puts "With OAUTH"
447
+ user = User.create(oauth_data: json_data)
448
+ puts user.errors.to_a
449
+ end
450
+
451
+ # create_user_without_oauth
452
+
453
+ create_user_with_facebook_oauth
454
+ puts "FB: #{ User.last.login }"
455
+ puts "FB: #{ User.last.email }"
456
+
457
+ create_user_with_vk_oauth
458
+ puts "VK: #{ User.last.login }"
459
+ puts "VK: #{ User.last.email }"
460
+
461
+ create_user_with_twitter_oauth
462
+ puts "TW: #{ User.last.login }"
463
+ puts "TW: #{ User.last.email }"
464
+
465
+ create_user_with_google_oauth
466
+ puts "G+: #{ User.last.login }"
467
+ puts "G+: #{ User.last.email }"
468
+
469
+ create_user_with_ok_oauth
470
+ puts "OK: #{ User.last.login }"
471
+ puts "OK: #{ User.last.email }"
472
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'the_social_login/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "the_social_login"
8
+ spec.version = TheSocialLogin::VERSION
9
+ spec.authors = ["Ilya N. Zykin"]
10
+ spec.email = ["zykin-ilya@ya.ru"]
11
+ spec.summary = %q{Model concern for OAuth}
12
+ spec.description = %q{Parse OAuth data}
13
+ spec.homepage = "https://github.com/TheProfitCMS/the_social_login"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "the_string_to_slug", "~> 1.2"
24
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_social_login
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ilya N. Zykin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: the_string_to_slug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ description: Parse OAuth data
56
+ email:
57
+ - zykin-ilya@ya.ru
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - app/models/concerns/social_networks_login_base.rb
68
+ - gem_version.rb
69
+ - lib/the_social_login.rb
70
+ - lib/the_social_login/version.rb
71
+ - spec/oauth_registration.rb
72
+ - the_social_login.gemspec
73
+ homepage: https://github.com/TheProfitCMS/the_social_login
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Model concern for OAuth
97
+ test_files:
98
+ - spec/oauth_registration.rb