nm-gigya 0.1.18 → 0.1.24
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 +4 -4
- data/lib/gigya/connection.rb +11 -2
- data/lib/gigya/controller_utils.rb +31 -9
- data/lib/gigya/user.rb +134 -4
- metadata +9 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 54da79569c7861797f22204107d2cc001dbb777df250f622123fcb21edf3310a
|
|
4
|
+
data.tar.gz: 55602a7160d4189029e993d82d9c1bbaeeda100f2ba26c28bc78652801ac5dbb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac671574e315d01ce33a9d08c92eff30af86bba8b98a2dd0f90936ac990717107617ef39a858fade4e4b7da13cea2305c1909bba5ca12b167dd0506a4aa9be0d
|
|
7
|
+
data.tar.gz: e7d9027175d69dca62093a65a91b21f494be4be4216db6dc7a3feb4864db36114059ee2b6e23e9b0656afe35d706d62f51c99f7b40de0439fd362395900a71de
|
data/lib/gigya/connection.rb
CHANGED
|
@@ -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" ?
|
|
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
|
-
|
|
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 =
|
|
55
|
-
token_location = :
|
|
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
|
data/lib/gigya/user.rb
CHANGED
|
@@ -50,7 +50,7 @@ module Gigya
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def reload
|
|
53
|
-
conn =
|
|
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 =
|
|
63
|
+
conn = my_gigya_connection
|
|
64
64
|
conn.api_post("accounts", "setAccountInfo", info)
|
|
65
65
|
save_to_cache
|
|
66
66
|
|
|
@@ -89,7 +89,7 @@ module Gigya
|
|
|
89
89
|
email = email.gsub('"', '') # get rid of quotes
|
|
90
90
|
opts = {} if opts.nil?
|
|
91
91
|
conn = opts[:connection] || Gigya::Connection.shared_connection
|
|
92
|
-
resp = conn.api_get("accounts", "search", {:query => "SELECT
|
|
92
|
+
resp = conn.api_get("accounts", "search", {:query => "SELECT UID FROM accounts WHERE profile.email = \"#{email}\""})
|
|
93
93
|
uid = resp["results"][0]["UID"] rescue nil
|
|
94
94
|
return nil if uid.blank?
|
|
95
95
|
return self.find(uid, opts)
|
|
@@ -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
|
-
|
|
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.
|
|
4
|
+
version: 0.1.24
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jonathan Bartlett
|
|
8
8
|
- Tyler Jackson
|
|
9
|
-
|
|
9
|
+
- Clark Ritchie
|
|
10
|
+
autorequire:
|
|
10
11
|
bindir: bin
|
|
11
12
|
cert_chain: []
|
|
12
|
-
date:
|
|
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@
|
|
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
|
-
|
|
74
|
-
|
|
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: []
|