gauthify 1.2.71 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gauthify.rb +100 -56
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e311b9a782b5ecd09e3c396f670053b37ec7a51f
|
4
|
+
data.tar.gz: 2e9a3a8aae36a74b92a5fb72469ff353632922e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 317cfeeeb825f60d20fad2e9f5c7fb6a38e709450b7e7a4cf604dc15588aa7b78ba049cae422ee078ab381919cfb661312aa383218c7509b0d62bdc3a08a4f8c
|
7
|
+
data.tar.gz: 33675608a87b5bb139e3fb43cd62ae3d5f7b1c7e97309aa4a28be64a4e7463371d6e2b3a1e66694eca0fbb3b05190233a6418e349729b4e09589a7cd22f43f12
|
data/lib/gauthify.rb
CHANGED
@@ -2,6 +2,7 @@ require 'net/http'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'rest-client'
|
4
4
|
require 'json'
|
5
|
+
require 'base64'
|
5
6
|
|
6
7
|
class GAuthifyError < Exception
|
7
8
|
<<-DOC
|
@@ -37,6 +38,12 @@ class NotFoundError < GAuthifyError
|
|
37
38
|
DOC
|
38
39
|
end
|
39
40
|
|
41
|
+
class ConflictError < GAuthifyError
|
42
|
+
<<-DOC
|
43
|
+
Raised when a conflicting resource exists (e.g. post an existing user)
|
44
|
+
DOC
|
45
|
+
end
|
46
|
+
|
40
47
|
|
41
48
|
class ServerError < GAuthifyError
|
42
49
|
<<-DOC
|
@@ -57,10 +64,11 @@ class GAuthify
|
|
57
64
|
|
58
65
|
def initialize(api_key)
|
59
66
|
@access_points = [
|
60
|
-
'https://
|
61
|
-
'https://
|
67
|
+
'https://alpha.gauthify.com/v1/',
|
68
|
+
'https://beta.gauthify.com/v1/'
|
62
69
|
]
|
63
|
-
@headers = {:authorization =>
|
70
|
+
@headers = {:authorization => "Basic #{Base64.encode64(":#{api_key}")}",
|
71
|
+
:user_agent => 'GAuthify-Ruby/v2.0'}
|
64
72
|
|
65
73
|
end
|
66
74
|
|
@@ -76,7 +84,7 @@ class GAuthify
|
|
76
84
|
rescue
|
77
85
|
json_resp = false
|
78
86
|
end
|
79
|
-
if not json_resp.is_a? Hash or (status_code > 400 and not [401, 402, 406, 404].include?(status_code))
|
87
|
+
if not json_resp.is_a? Hash or (status_code > 400 and not [401, 402, 406, 404, 409].include?(status_code))
|
80
88
|
raise RestClient::Exception
|
81
89
|
end
|
82
90
|
break
|
@@ -95,6 +103,9 @@ class GAuthify
|
|
95
103
|
when 404
|
96
104
|
json_resp = JSON.parse(e.http_body)
|
97
105
|
raise NotFoundError.new(json_resp['error_message'], status_code, json_resp['error_code'], e.http_body), json_resp['error_message']
|
106
|
+
when 409
|
107
|
+
json_resp = JSON.parse(e.http_body)
|
108
|
+
raise ConflictError.new(json_resp['error_message'], status_code, json_resp['error_code'], e.http_body), json_resp['error_message']
|
98
109
|
end
|
99
110
|
end
|
100
111
|
if each == @access_points[-1]
|
@@ -108,23 +119,29 @@ class GAuthify
|
|
108
119
|
end
|
109
120
|
|
110
121
|
|
111
|
-
def create_user(unique_id, display_name, email=nil,
|
122
|
+
def create_user(unique_id, display_name, email=nil, sms_number=nil, voice_number=nil, meta=nil)
|
112
123
|
<<-DOC
|
113
|
-
Creates new user
|
124
|
+
Creates new user
|
114
125
|
DOC
|
115
126
|
|
116
|
-
params = {'display_name' => display_name}
|
127
|
+
params = {'unique_id' => unique_id, 'display_name' => display_name}
|
117
128
|
if email
|
118
129
|
params['email'] = email
|
119
130
|
end
|
120
|
-
if
|
121
|
-
params['
|
131
|
+
if sms_number
|
132
|
+
params['sms_number'] = sms_number
|
122
133
|
end
|
123
|
-
|
134
|
+
if voice_number
|
135
|
+
params['voice_number'] = voice_number
|
136
|
+
end
|
137
|
+
if meta
|
138
|
+
params['meta'] = meta.to_json
|
139
|
+
end
|
140
|
+
url_addon = "users/"
|
124
141
|
return requests_handler('post', url_addon, params=params)
|
125
142
|
end
|
126
143
|
|
127
|
-
def update_user(unique_id, email=nil,
|
144
|
+
def update_user(unique_id, email=nil, sms_number=nil, voice_number=nil, meta=nil, reset_key = false)
|
128
145
|
<<-DOC
|
129
146
|
Creates new user with a new secret key or resets if already exists
|
130
147
|
DOC
|
@@ -133,8 +150,11 @@ class GAuthify
|
|
133
150
|
if email
|
134
151
|
params['email'] = email
|
135
152
|
end
|
136
|
-
if
|
137
|
-
params['
|
153
|
+
if sms_number
|
154
|
+
params['sms_number'] = sms_number
|
155
|
+
end
|
156
|
+
if voice_number
|
157
|
+
params['voice_number'] = voice_number
|
138
158
|
end
|
139
159
|
if meta
|
140
160
|
params['meta'] = meta.to_json
|
@@ -142,7 +162,6 @@ class GAuthify
|
|
142
162
|
if reset_key
|
143
163
|
params['reset_key'] = 'true'
|
144
164
|
end
|
145
|
-
puts params
|
146
165
|
url_addon = "users/#{unique_id}/"
|
147
166
|
return requests_handler('put', url_addon, params=params)
|
148
167
|
end
|
@@ -165,21 +184,21 @@ class GAuthify
|
|
165
184
|
end
|
166
185
|
|
167
186
|
|
168
|
-
def get_user(unique_id
|
187
|
+
def get_user(unique_id)
|
169
188
|
<<-DOC
|
170
|
-
Returns a single user
|
189
|
+
Returns a single user
|
171
190
|
DOC
|
172
191
|
url_addon = "users/#{unique_id}/"
|
173
|
-
url_addon << "check/#{auth_code}" if auth_code
|
174
192
|
return requests_handler('get', url_addon)
|
175
193
|
end
|
176
194
|
|
177
|
-
def get_user_by_token(
|
195
|
+
def get_user_by_token(token)
|
178
196
|
<<-DOC
|
179
197
|
Returns a single user by ezGAuth token
|
180
198
|
DOC
|
181
|
-
|
182
|
-
|
199
|
+
params = {'token' => token}
|
200
|
+
url_addon = "token/"
|
201
|
+
return requests_handler('post', url_addon, params=params)
|
183
202
|
end
|
184
203
|
|
185
204
|
def check_auth(unique_id, auth_code, safe_mode = false)
|
@@ -187,10 +206,9 @@ class GAuthify
|
|
187
206
|
Checks OTP returns True/False depending on OTP correctness.
|
188
207
|
DOC
|
189
208
|
begin
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
end
|
209
|
+
url_addon = "check/"
|
210
|
+
params = {'unique_id' => unique_id, 'auth_code' => auth_code}
|
211
|
+
response = requests_handler('post', url_addon, params=params)
|
194
212
|
return response['authenticated']
|
195
213
|
rescue GAuthifyError => e
|
196
214
|
if safe_mode
|
@@ -202,27 +220,40 @@ class GAuthify
|
|
202
220
|
|
203
221
|
end
|
204
222
|
|
223
|
+
def send_email(unique_id, email = nil)
|
224
|
+
<<-DOC
|
225
|
+
Sends email with the one time auth_code
|
226
|
+
DOC
|
227
|
+
url_addon = "email/"
|
228
|
+
params = {'unique_id' => unique_id}
|
229
|
+
if email
|
230
|
+
params['email'] = email
|
231
|
+
end
|
232
|
+
return requests_handler('post', url_addon, params=params)
|
233
|
+
end
|
205
234
|
|
206
|
-
def send_sms(unique_id,
|
235
|
+
def send_sms(unique_id, sms_number = nil)
|
207
236
|
<<-DOC
|
208
237
|
Sends text message to phone number with the one time auth_code
|
209
238
|
DOC
|
210
|
-
url_addon = "
|
211
|
-
|
212
|
-
|
239
|
+
url_addon = "sms/"
|
240
|
+
params = {'unique_id' => unique_id}
|
241
|
+
if sms_number
|
242
|
+
params['sms_number'] = sms_number
|
213
243
|
end
|
214
|
-
return requests_handler('
|
244
|
+
return requests_handler('post', url_addon, params=params)
|
215
245
|
end
|
216
246
|
|
217
|
-
def
|
247
|
+
def send_voice(unique_id, voice_number = nil)
|
218
248
|
<<-DOC
|
219
|
-
|
249
|
+
Makes a call to phone number with the one time auth_code
|
220
250
|
DOC
|
221
|
-
url_addon = "
|
222
|
-
|
223
|
-
|
251
|
+
url_addon = "voice/"
|
252
|
+
params = {'unique_id' => unique_id}
|
253
|
+
if voice_number
|
254
|
+
params['voice_number'] = voice_number
|
224
255
|
end
|
225
|
-
return requests_handler('
|
256
|
+
return requests_handler('post', url_addon, params=params)
|
226
257
|
end
|
227
258
|
|
228
259
|
def api_errors()
|
@@ -234,11 +265,15 @@ class GAuthify
|
|
234
265
|
end
|
235
266
|
|
236
267
|
|
237
|
-
def quick_test(test_email = nil,
|
268
|
+
def quick_test(test_email = nil, test_sms_number = nil, test_voice_number = nil)
|
238
269
|
<<-DOC
|
239
270
|
Runs initial tests to make sure everything is working fine
|
240
271
|
DOC
|
241
272
|
account_name = 'testuser@gauthify.com'
|
273
|
+
begin
|
274
|
+
delete_user(account_name)
|
275
|
+
rescue NotFoundError => e
|
276
|
+
end
|
242
277
|
|
243
278
|
def success()
|
244
279
|
print("Success \n")
|
@@ -246,8 +281,10 @@ class GAuthify
|
|
246
281
|
|
247
282
|
puts("1) Testing Creating a User...")
|
248
283
|
result = create_user(account_name,
|
249
|
-
account_name,
|
250
|
-
|
284
|
+
account_name,
|
285
|
+
email='firsttest@gauthify.com',
|
286
|
+
sms_number='9162627232',
|
287
|
+
voice_number='9162627233')
|
251
288
|
if not result['unique_id'] == account_name
|
252
289
|
raise Exception
|
253
290
|
end
|
@@ -257,7 +294,10 @@ class GAuthify
|
|
257
294
|
if not result['email'] == 'firsttest@gauthify.com'
|
258
295
|
raise Exception
|
259
296
|
end
|
260
|
-
if not result['
|
297
|
+
if not result['sms_number'] == '+19162627232'
|
298
|
+
raise Exception
|
299
|
+
end
|
300
|
+
if not result['voice_number'] == '+19162627233'
|
261
301
|
raise Exception
|
262
302
|
end
|
263
303
|
puts(result)
|
@@ -300,26 +340,30 @@ class GAuthify
|
|
300
340
|
puts(result)
|
301
341
|
success()
|
302
342
|
end
|
303
|
-
if
|
304
|
-
puts("5B) Testing SMS to #{
|
305
|
-
send_sms(account_name,
|
343
|
+
if test_sms_number
|
344
|
+
puts("5B) Testing SMS to #{test_sms_number}")
|
345
|
+
send_sms(account_name, test_sms_number)
|
306
346
|
success()
|
307
347
|
end
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
348
|
+
if test_voice_number
|
349
|
+
puts("5C) Calling #{test_voice_number}")
|
350
|
+
send_voice(account_name, test_voice_number)
|
351
|
+
success()
|
312
352
|
end
|
313
|
-
puts(result)
|
314
|
-
success()
|
315
353
|
|
316
|
-
puts("
|
317
|
-
result = update_user(account_name,
|
318
|
-
|
354
|
+
puts("6) Testing updating email, phone, and meta")
|
355
|
+
result = update_user(account_name,
|
356
|
+
email='test@gauthify.com',
|
357
|
+
sms_number='9162627235',
|
358
|
+
voice_number='9162627236',
|
359
|
+
meta={'a' => 'b'})
|
319
360
|
if not result['email'] == 'test@gauthify.com'
|
320
361
|
raise Exception
|
321
362
|
end
|
322
|
-
if not result['
|
363
|
+
if not result['sms_number'] == '+19162627235'
|
364
|
+
raise Exception
|
365
|
+
end
|
366
|
+
if not result['voice_number'] == '+19162627236'
|
323
367
|
raise Exception
|
324
368
|
end
|
325
369
|
if not result['meta']['a'] == 'b'
|
@@ -328,19 +372,19 @@ class GAuthify
|
|
328
372
|
current_key = result['key']
|
329
373
|
success()
|
330
374
|
|
331
|
-
puts("
|
332
|
-
result = update_user(account_name, nil, nil, nil, true)
|
375
|
+
puts("7) Testing key/secret")
|
376
|
+
result = update_user(account_name, nil, nil, nil, nil, true)
|
333
377
|
puts(current_key, result['key'])
|
334
378
|
if not result['key'] != current_key
|
335
379
|
raise Exception
|
336
380
|
end
|
337
381
|
success()
|
338
382
|
|
339
|
-
puts("
|
383
|
+
puts("8) Deleting Created User...")
|
340
384
|
result = delete_user(account_name)
|
341
385
|
success()
|
342
386
|
|
343
|
-
puts("
|
387
|
+
puts("9) Testing backup server...")
|
344
388
|
current = @access_points[0]
|
345
389
|
@access_points[0] = 'https://blah.gauthify.com/v1/'
|
346
390
|
result = get_all_users()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gauthify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GAuthify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|