nm-gigya 0.1.21 → 0.1.27

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
2
  SHA256:
3
- metadata.gz: 16a25e8dd7145c0f168abd4cb48d5a0015e36acf5b5875ab14847cd409da1517
4
- data.tar.gz: 89575031565c30fece68f11d68cfb2c172c955861468890a1b4dd347cb5df555
3
+ metadata.gz: 61fbfb7bec7e916ebbd5ead7bb06bf5b2fef9af53cdc69e21bbd025f2f6b2012
4
+ data.tar.gz: b00fd8f43838915f463aa3a2381d502f63ab1ce689098581855752f2ca80e782
5
5
  SHA512:
6
- metadata.gz: a3afe07e75ba869edfd28d40560c1355e6fdfac5e724be115dd9a31a3c36c7626ad1c8be98251a95714f0b37bfd9f3d5f0a6cb0605525dbcdf53298ff2737236
7
- data.tar.gz: 3b41ed2716229a0a4c9c7b5b13a0f874977b42a5e4673d9df01e15184ceb707368e833bd0c2b9adef5080063a9823f8daa474b2d9512be85f49e560c89ab5377
6
+ metadata.gz: b1b1f8116726ca576f215dad676c28647bde63144bf799f1c3e6ef7897a72cbe5247359df843b984105f17d14a02c8ad96b7070ea407576db351dbfaed397eda
7
+ data.tar.gz: 7cf1fe69e6e457d2ba4116f316db28cb4893b47cd347a7685624e311e2b6eb6e014d5f0f7f4efd9e1a7131e90a09bccb9af77a9f0ff351a6939a130f5df08436
@@ -153,6 +153,7 @@ module Gigya
153
153
 
154
154
  class Connection
155
155
  attr_accessor :jwt_skip_validation
156
+ attr_accessor :whitelisted_api_keys
156
157
 
157
158
  GIGYA_BASE_URL="gigya.com"
158
159
  def self.shared_connection
@@ -164,6 +165,10 @@ module Gigya
164
165
  :user_secret => ENV["GIGYA_USER_SECRET"],
165
166
  :debug_connection => ENV["GIGYA_DEBUG_CONNECTION"] == "1"
166
167
  )
168
+
169
+ whitelist = ENV["GIGYA_WHITELISTED_API_KEYS"]
170
+ conn.whitelisted_api_keys = whitelist.split(",") unless whitelist.blank?
171
+
167
172
  conn.jwt_skip_validation = false
168
173
  conn
169
174
  end
@@ -263,6 +268,18 @@ module Gigya
263
268
 
264
269
  return user_jwt_info if jwt_skip_validation
265
270
 
271
+ # If we have enumerated whitelisted API keys
272
+ unless whitelisted_api_keys.nil?
273
+ # Grab the API key encoded in the token
274
+ jwt_api_key = user_jwt_info["apiKey"]
275
+
276
+ # Our own API key is automatically valid
277
+ if jwt_api_key != api_key
278
+ # Make sure it is listed in the whitelisted keys
279
+ raise "Invalid API Key" unless whitelisted_api_keys.include?(jwt_api_key)
280
+ end
281
+ end
282
+
266
283
  signing_key_id = signing_jwt_info["keyid"]
267
284
  @cached_data["jwt_public_keys"] ||= {}
268
285
  k = @cached_data["jwt_public_keys"][signing_key_id]
@@ -292,6 +309,15 @@ module Gigya
292
309
  api_call("POST", area, function, params, opts)
293
310
  end
294
311
 
312
+ # This allows substituting how HTTP calls are made (could be useful for testing)
313
+ def http_driver
314
+ @http_driver || HTTParty
315
+ end
316
+
317
+ def http_driver=(val)
318
+ @http_driver = val
319
+ end
320
+
295
321
  def api_call(http_method, area, function, params = nil, opts = nil)
296
322
  params ||= {}
297
323
  opts ||= {}
@@ -302,7 +328,7 @@ module Gigya
302
328
  params[:apiKey] = opts[:api_key]
303
329
  unless opts[:authenticate_app] == false
304
330
  params[:secret] = opts[:user_secret]
305
- params[:userKey] = opts[:user_key]
331
+ params[:userKey] = opts[:user_key] unless opts[:user_key].blank?
306
332
  end
307
333
 
308
334
  if opts[:session] != nil
@@ -319,7 +345,7 @@ module Gigya
319
345
  end
320
346
  http_response = nil
321
347
  response = begin
322
- http_response = http_method == "GET" ? HTTParty.get(base_url, :query => params) : HTTParty.post(base_url, :body => params)
348
+ http_response = http_method == "GET" ? http_driver.get(base_url, :query => params) : http_driver.post(base_url, :body => params)
323
349
  JSON.parse(http_response.body)
324
350
  rescue
325
351
  {"errorCode" => 600, "errorMessage" => "Unknown error", "errorDetail" => "Unable to communicate with authentication server", :http => http_response.inspect}
@@ -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,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nm-gigya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Bartlett
8
8
  - Tyler Jackson
9
9
  - Clark Ritchie
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-02-07 00:00:00.000000000 Z
13
+ date: 2020-04-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -40,8 +40,8 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '2.1'
43
- description:
44
- email: jonathan@newmedio.com
43
+ description:
44
+ email: jonathan.bartlett@specialized.com
45
45
  executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
@@ -56,7 +56,7 @@ homepage: http://www.newmedio.com/
56
56
  licenses:
57
57
  - MIT
58
58
  metadata: {}
59
- post_install_message:
59
+ post_install_message:
60
60
  rdoc_options: []
61
61
  require_paths:
62
62
  - lib
@@ -71,8 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.0.2
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: []