nm-gigya 0.1.19 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0547a27ef1dca0470d42912f8e9292dd4a5d3e11
4
- data.tar.gz: 81e8d1d1216a17ef991ae24862c861dce56d53fc
2
+ SHA256:
3
+ metadata.gz: 408cd9ea838368a5276a96875eb10a42c0829788b62ddb2aa59b82a3590da6ad
4
+ data.tar.gz: d1d6049f5832d881153513a27b4fa7accc439ab63e223ab7ea15f4d1982ed590
5
5
  SHA512:
6
- metadata.gz: 56a6181bffe5a21a7bcd713fabfb03d04ae15298182e99629bcb5f9a37dbba17d70d5a6919985b45d487db02784f101728de2ba0a5c2bcc33783b76acc3fb774
7
- data.tar.gz: 632d72a10c0e03eaec22e59fba00804ca498a29e55cc6e50abd434ad38b17278e57edafe80b7f0b020ad5ef26a852d9332a828b78160175668bb883c98124e04
6
+ metadata.gz: 21cea382f67d531034a4876241f2fe081f389913cc64f3afbff9676c8a8904d9fe378e894cf217779b91ef9d07a99f7976c8409f5bec987a02bc415b3bcce3cb
7
+ data.tar.gz: 757daaab8ac6695caa7a4fe069d99ded456d45e57ebbe018e9baf05061bb399fbc1580d10e9438f71cb7139f5d82da07065edc0e30d58073782b900ad581fe29
@@ -292,6 +292,15 @@ module Gigya
292
292
  api_call("POST", area, function, params, opts)
293
293
  end
294
294
 
295
+ # This allows substituting how HTTP calls are made (could be useful for testing)
296
+ def http_driver
297
+ @http_driver || HTTParty
298
+ end
299
+
300
+ def http_driver=(val)
301
+ @http_driver = val
302
+ end
303
+
295
304
  def api_call(http_method, area, function, params = nil, opts = nil)
296
305
  params ||= {}
297
306
  opts ||= {}
@@ -302,7 +311,7 @@ module Gigya
302
311
  params[:apiKey] = opts[:api_key]
303
312
  unless opts[:authenticate_app] == false
304
313
  params[:secret] = opts[:user_secret]
305
- params[:userKey] = opts[:user_key]
314
+ params[:userKey] = opts[:user_key] unless opts[:user_key].blank?
306
315
  end
307
316
 
308
317
  if opts[:session] != nil
@@ -319,7 +328,7 @@ module Gigya
319
328
  end
320
329
  http_response = nil
321
330
  response = begin
322
- http_response = http_method == "GET" ? HTTParty.get(base_url, :query => params) : HTTParty.post(base_url, :body => params)
331
+ http_response = http_method == "GET" ? http_driver.get(base_url, :query => params) : http_driver.post(base_url, :body => params)
323
332
  JSON.parse(http_response.body)
324
333
  rescue
325
334
  {"errorCode" => 600, "errorMessage" => "Unknown error", "errorDetail" => "Unable to communicate with authentication server", :http => http_response.inspect}
@@ -23,10 +23,30 @@ module Gigya
23
23
  @@gigya_refresh_time_decay
24
24
  end
25
25
 
26
+ @@max_logged_tokens = 20
27
+ @@logged_tokens = {}
28
+
29
+ def log_token_error(tok, msg = nil)
30
+ if @@max_logged_tokens > 0
31
+ if @@logged_tokens[tok]
32
+ # already logged
33
+ else
34
+ @@logged_tokens[tok] = true
35
+ @@max_logged_tokens = @@max_logged_tokens - 1
36
+ end
37
+ Rails.logger.warn("Token Issue: #{tok}") if tok.present?
38
+ Rails.logger.warn("Token message: #{msg}") if msg.present?
39
+ end
40
+ end
41
+
26
42
  def gigya_user_required
27
43
  begin
28
- render(:json => {:error => "Invalid login"}, :status => 401) if gigya_user_identifier.blank?
44
+ if gigya_user_identifier.blank?
45
+ log_token_error(request.headers["Authorization"])
46
+ render(:json => {:error => "Invalid login"}, :status => 401)
47
+ end
29
48
  rescue
49
+ log_token_error(request.headers["Authorization"], $!.message)
30
50
  render(:json => {:error => "#{$!.message}"}, :status => 401)
31
51
  end
32
52
  end
@@ -48,11 +68,13 @@ module Gigya
48
68
  end
49
69
 
50
70
  begin
51
- tmp_token = params[GIGYA_QUERY_PARAM] unless params[GIGYA_QUERY_PARAM].blank?
52
- token_location = :param
53
71
  if tmp_token.blank?
54
- tmp_token = cookies[GIGYA_COOKIE_PARAM]
55
- token_location = :cookie
72
+ tmp_token = params[GIGYA_QUERY_PARAM] unless params[GIGYA_QUERY_PARAM].blank?
73
+ token_location = :param
74
+ if tmp_token.blank?
75
+ tmp_token = cookies[GIGYA_COOKIE_PARAM]
76
+ token_location = :cookie
77
+ end
56
78
  end
57
79
  rescue
58
80
  # Some lightweight controllers don't do cookies
@@ -60,7 +82,7 @@ module Gigya
60
82
 
61
83
  begin
62
84
  if tmp_token.blank?
63
- tmp_token = session[GIGYA_SESSION_PARAM]
85
+ tmp_token = session[GIGYA_SESSION_PARAM]
64
86
  token_location = :session
65
87
  end
66
88
  rescue
@@ -76,7 +98,7 @@ module Gigya
76
98
  end
77
99
 
78
100
  def interpret_jwt_token(force = false)
79
- if @gigya_jwt_info.nil?
101
+ if @gigya_jwt_info.nil?
80
102
  @gigya_jwt_info = Gigya::Connection.shared_connection.validate_jwt(gigya_jwt_token)
81
103
 
82
104
  perform_token_refresh if needs_token_refresh?
@@ -112,7 +134,7 @@ module Gigya
112
134
  case @gigya_token_location
113
135
  when :header
114
136
  headers["X-Set-Authorization-Token"] = token
115
- headers["X-Set-Authorization-Token-Expiration"] = expiration_time.to_i
137
+ headers["X-Set-Authorization-Token-Expiration"] = expiration_time.to_i.to_s
116
138
  when :cookie
117
139
  cookies[GIGYA_COOKIE_PARAM] = token
118
140
  when :session
@@ -158,5 +180,5 @@ module Gigya
158
180
  @gigya_jwt_info["sub"]
159
181
  end
160
182
  end
161
- end
183
+ end
162
184
  end
@@ -50,7 +50,7 @@ module Gigya
50
50
  end
51
51
 
52
52
  def reload
53
- conn = gigya_connection || Gigya::Connection.shared_connection
53
+ conn = my_gigya_connection
54
54
  set_attributes(conn.api_get("accounts", "getAccountInfo", {UID: uid, include:"profile,data,subscriptions,userInfo,preferences", extraProfileFields:@@extra_profile_fields.join(",")}))
55
55
  end
56
56
 
@@ -60,7 +60,7 @@ module Gigya
60
60
  info["data"] = gigya_details["data"].to_json if gigya_details["data"].present?
61
61
  # What about isActive, isVerified?, password/newPassword, preferences, add/removeLoginEmails, subscriptions, lang, rba
62
62
 
63
- conn = gigya_connection || Gigya::Connection.shared_connection
63
+ conn = my_gigya_connection
64
64
  conn.api_post("accounts", "setAccountInfo", info)
65
65
  save_to_cache
66
66
 
@@ -97,7 +97,7 @@ module Gigya
97
97
 
98
98
  def self.find(uid, opts = {}) # Find a Gigya account record by its UID attribute
99
99
  opts = {} if opts.nil?
100
- opts[:cache] = true if opts[:cache].nil?
100
+ opts[:cache] = true if opts[:cache].nil?
101
101
 
102
102
  cache_info = load_from_cache(uid)
103
103
  if cache_info.present? && opts[:cache]
@@ -163,5 +163,135 @@ module Gigya
163
163
  nil
164
164
  end
165
165
  end
166
+
167
+
168
+ # Intended way of calling this:
169
+ # Gigya::User.create_gigya_user_through_notify_login("abc@example.com", :password => "Abc123!!", :account => { "preferences" => {"foo" => "bar" } }, :verified => true)
170
+ #
171
+ # Options:
172
+ # :password => Set a password,
173
+ # :source => the registration source
174
+ # :account => hash of any account defaults you want to set. Profile defaults should be under the "profile" key.
175
+ # :send_verification => Will send verification email
176
+ # :verified => Will auto-set "verified"
177
+ # :force => Will do things that Gigya doesn't naturally want to do (often used in combination with :verified)
178
+ # :debug => will print out call information
179
+
180
+ # Creates a gigya user through the `notify_login` pathway
181
+ def self.create_gigya_user_through_notify_login(email, opts = {})
182
+ conn = opts[:gigya_connection] || Gigya::Connection.shared_connection
183
+
184
+ # Create UUID
185
+ new_uid = opts[:UID] || "#{SecureRandom.uuid.gsub("-", "")}#{SecureRandom.uuid.gsub("-", "")}"
186
+
187
+ # Is the address available?
188
+ email_is_available = conn.api_get("accounts", "isAvailableLoginID", { "loginID" => email }, :debug_connection => opts[:debug])["isAvailable"] rescue false
189
+ raise "Username is unavailable" unless email_is_available
190
+
191
+ # Register UUID
192
+ response = conn.api_get("accounts", "notifyLogin", {"siteUID" => new_uid}, :debug_connection => opts[:debug])
193
+ raise "Could not register UID" unless response["errorCode"] == 0 || response["errorCode"] == 206001
194
+
195
+ # Start the registration process
196
+ regtoken = conn.api_get("accounts", "initRegistration", {}, :debug_connection => opts[:debug])["regToken"] rescue nil
197
+ raise "Could not initiate registration" if regtoken.blank?
198
+
199
+ # Create the data record
200
+ account_info = opts[:account] || {} # This allows the caller to send us defaults
201
+ account_info["UID"] = new_uid # Primary key
202
+ account_info["regToken"] = regtoken # Ties it to the initial registration
203
+ account_info["securityOverride"] = true # Allows us to set passwords if we want
204
+ account_info["profile"] ||= {}
205
+ account_info["profile"]["email"] = email # Actual login username
206
+ account_info["profile"] = account_info["profile"].to_json
207
+ account_info["preferences"] = account_info["preferences"].to_json
208
+ account_info["regSource"] = opts[:source] || "nm-gigya"
209
+
210
+ # Optional data record pieces
211
+ account_info["isVerified"] = true if opts[:verified]
212
+ account_info["newPassword"] = opts[:password] unless opts[:password].blank?
213
+
214
+ # Create the registration with the data record
215
+ results = conn.api_post("accounts", "setAccountInfo", account_info, :debug_connection => opts[:debug])
216
+
217
+ # If not everything got set correctly (NOTE - doesn't work if :password is not also sent)
218
+ if opts[:force]
219
+ response = conn.api_get("accounts", "login", {"loginID" => email, "password" => opts[:password]}, :debug_connection => opts[:debug])
220
+ if response["errorCode"] != 0
221
+ verify_reg_token = response["regToken"]
222
+ response = conn.api_get("accounts", "finalizeRegistration", {"regToken" => verify_reg_token, "include" => "emails, profile"}, :debug_connection => opts[:debug])
223
+ unless response["errorCode"] == 0 || response["errorCode"] == 206002 || response["errorCode"] == 206001
224
+ raise "Unable to finalize registration"
225
+ end
226
+ end
227
+ end
228
+
229
+ if opts[:send_verification]
230
+ conn.api_get("accounts", "resendVerificationCode", {"UID" => new_uid, "email" => email})
231
+ end
232
+
233
+ if opts[:send_password_change]
234
+ conn.api_get("accounts", "resetPassword", {"UID" => new_uid, "loginID" => email, "email" => email})
235
+ end
236
+
237
+ return new_uid
238
+ end
239
+
240
+ # Creates a gigya user through the `register` pathway
241
+
242
+ # Options:
243
+ # :password => Set a password,
244
+ # :source => the registration source
245
+ # :account => hash of any account defaults you want to set. Profile defaults should be under the "profile" key.
246
+ # :debug => will print out call information
247
+
248
+ def self.create_gigya_user_through_register(email, opts = {})
249
+ conn = opts[:gigya_connection] || Gigya::Connection.shared_connection
250
+
251
+ new_password = opts[:password] || SecureRandom.urlsafe_base64(8)
252
+
253
+ # Create UUID
254
+ new_uid = opts[:UID] || "#{SecureRandom.uuid.gsub("-", "")}#{SecureRandom.uuid.gsub("-", "")}"
255
+
256
+ # Is the address available?
257
+ email_is_available = conn.api_get("accounts", "isAvailableLoginID", { "loginID" => email }, :debug_connection => opts[:debug])["isAvailable"] rescue false
258
+ raise "Username is unavailable" unless email_is_available
259
+
260
+ # Start the registration process
261
+ regtoken = conn.api_get("accounts", "initRegistration", {}, :debug_connection => opts[:debug])["regToken"] rescue nil
262
+ raise "Could not initiate registration" if regtoken.blank?
263
+
264
+ # Create the data record
265
+ account_info = opts[:account] || {} # This allows the caller to send us defaults
266
+ account_info["siteUID"] = new_uid # Primary key
267
+ account_info["regToken"] = regtoken # Ties it to the initial registration
268
+ account_info["profile"] ||= {}
269
+ account_info["email"] = email
270
+ account_info["profile"]["email"] = email # Actual login username
271
+ account_info["profile"] = account_info["profile"].to_json
272
+ account_info["preferences"] = account_info["preferences"].to_json unless account_info["preferences"].nil?
273
+ account_info["regSource"] = opts[:source] unless opts[:source].blank?
274
+ account_info["password"] = new_password
275
+ account_info["data"] = account_info["data"].to_json unless account_info["data"].nil?
276
+
277
+ # Complete the registration process
278
+ conn.api_post("accounts", "register", account_info, :debug_connection => opts[:debug])
279
+
280
+ if opts[:send_verification]
281
+ conn.api_get("accounts", "resendVerificationCode", {"UID" => new_uid, "email" => email})
282
+ end
283
+
284
+ if opts[:send_password_change]
285
+ conn.api_get("accounts", "resetPassword", {"UID" => new_uid, "loginID" => email, "email" => email})
286
+ end
287
+
288
+ return new_uid
289
+ end
290
+
291
+ private
292
+
293
+ def my_gigya_connection
294
+ gigya_connection || Gigya::Connection.shared_connection
295
+ end
166
296
  end
167
297
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nm-gigya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bartlett
8
8
  - Tyler Jackson
9
- autorequire:
9
+ - Clark Ritchie
10
+ autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2019-02-07 00:00:00.000000000 Z
13
+ date: 2020-04-22 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: httparty
@@ -39,8 +40,8 @@ dependencies:
39
40
  - - "~>"
40
41
  - !ruby/object:Gem::Version
41
42
  version: '2.1'
42
- description:
43
- email: jonathan@newmedio.com
43
+ description:
44
+ email: jonathan.bartlett@specialized.com
44
45
  executables: []
45
46
  extensions: []
46
47
  extra_rdoc_files: []
@@ -55,7 +56,7 @@ homepage: http://www.newmedio.com/
55
56
  licenses:
56
57
  - MIT
57
58
  metadata: {}
58
- post_install_message:
59
+ post_install_message:
59
60
  rdoc_options: []
60
61
  require_paths:
61
62
  - lib
@@ -70,9 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  - !ruby/object:Gem::Version
71
72
  version: '0'
72
73
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 2.5.2.1
75
- signing_key:
74
+ rubygems_version: 3.1.2
75
+ signing_key:
76
76
  specification_version: 4
77
77
  summary: Gigya API Utility Package
78
78
  test_files: []