authful 0.5.16 → 0.5.17

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mzk1MTg5YzRkMzFmZTc0Mjg1NjBhZDE4NDJhZjQyODRhY2EwZDFkNA==
4
+ ZGUxMTM0ZGY1OWJiZTgzNzZhNDEyYTAxZGMwNjVjMWMwMGYwMjNlYw==
5
5
  data.tar.gz: !binary |-
6
- YWNjOGNkMmMyMzM0ODhjNTkxMWM5OTE0MzFkNDFlZDY0NjU3NGRmOQ==
6
+ NTI3OThlNzgwMzY5YjU2NjE3NjY1NDExZGQzZjM5OTQwNDBkYmYyNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDgxOWE5Y2IyYWRiNjYxOWVjMTkxZDY0Yzg2YzhlZTAyODkzNGIzNWE3NDE3
10
- MmU0YzRjZTM1ZDViMzc0MTAyZDY4YmU4NGNhMzBiNWY5MTQzZmY5YThhMzM1
11
- YWVlY2E1MjZjMDk1YjE4YjMzZjJlY2FlYzI2MGNjMDU5ZWFmN2I=
9
+ OGU2NzdiZmVmNzBkM2EyNmVmNDk0Y2UzMDg4ZThlNGU5ZDUzM2QyNzU3N2Y5
10
+ NzhjYTczZGQ0M2Y5ZDQ0ODEwZDk5OWRmYjE0NzJmNDU4NTgxZTI2ODA5NzNh
11
+ NmEwMzAxYzQxYTJjN2NjYWI5NDQ2OWQ4N2NjMGU2MzdlZGUxZTI=
12
12
  data.tar.gz: !binary |-
13
- YTNiZDlmZDQyZjRjNDFiYjVjYmZlMGFkYjEzMDc4MDIzNzI0NmI1MTUxZjZi
14
- NGQzYzI1MzcxY2UwYzM4YzBhZDgyYmJiZTM1NWJhMGMzYzI5ZjhmMDUyYTlh
15
- Zjc3MGExYjQxODY1NzNiMmEwYjU2OTE0NTNlMGJmMTZjNWYyYjU=
13
+ Mjc1MTYyYjU1OGI4MTgwMWNlOTQzNTM0ZTBiNjRjNGVlZjhkNGFkMTcxMzIy
14
+ YTc1N2QyZWFhYTkzYTIxZDczOWY5ZTZhYTgzOTI1ZWY1Y2RjMWNhZmZiMTE2
15
+ ZmM3MDMxNjQwODc2MjY5ODViNjU5MDIwMTgzMTlkNGEzMjM5M2Q=
data/lib/authful/api.rb CHANGED
@@ -27,6 +27,15 @@ module Authful
27
27
  return Authful::Response.new(token: res["token"], qr_code: res["qr_code"], error: res["error"])
28
28
  end
29
29
 
30
+ def generate_recovery_codes(token)
31
+ res = Authful.send_request(:post, "/api/users/#{token}/recovery_codes")
32
+ res["recovery_codes"]
33
+ end
34
+
35
+ def validate_recovery_code(token, code)
36
+ Authful.send_request(:get, "/api/users/#{token}/recovery_codes?code=#{code}")["ok"] == 1
37
+ end
38
+
30
39
  def unenroll(token)
31
40
  Authful.send_request(:delete, "/api/users/#{token}")["ok"] == 1
32
41
  end
@@ -34,6 +34,9 @@ module Authful
34
34
  raise Authful::Errors::IncorrectApiToken
35
35
  elsif error.http_code == 403
36
36
  JSON.parse($!.response)
37
+ elsif error.http_code == 404
38
+ raise Authful::Errors::InvalidUserToken
39
+ JSON.parse($!.response)
37
40
  elsif error.http_code == 409
38
41
  JSON.parse($!.response)
39
42
  else
data/lib/authful.rb CHANGED
@@ -13,6 +13,7 @@ module Authful
13
13
  class IncorrectApiToken < RuntimeError; end
14
14
  class InvalidUserToken < RuntimeError; end
15
15
  class InvallidOtpToken < RuntimeError; end
16
+ class InvallidRecoveryCode < RuntimeError; end
16
17
  class AlreadyEnrolled < RuntimeError; end
17
18
  end
18
19
  end
@@ -77,7 +77,25 @@ describe Authful do
77
77
  it "sets phone number for user" do
78
78
  FakeWeb.register_uri :patch, "https://my-endpoint.dev/authful/api/users/user-authful-token/phone", {body: {ok: 1}.to_json}
79
79
 
80
- res = Authful.set_phone("user-authful-token", "12005551212").should eq(true)
80
+ Authful.set_phone("user-authful-token", "12005551212").should eq(true)
81
+ end
82
+
83
+ it "generates recovery codes" do
84
+ FakeWeb.register_uri :post, "https://my-endpoint.dev/authful/api/users/user-authful-token/recovery_codes", {body: {ok: 1, recovery_codes: ["00000 11111 22222"]}.to_json}
85
+
86
+ Authful.generate_recovery_codes("user-authful-token").length.should eq(1)
87
+ end
88
+
89
+ it "validates recovery code" do
90
+ FakeWeb.register_uri :get, "https://my-endpoint.dev/authful/api/users/user-authful-token/recovery_codes?code=000001111122222", {body: {ok: 1}.to_json}
91
+
92
+ Authful.validate_recovery_code("user-authful-token", "000001111122222").should eq(true)
93
+ end
94
+
95
+ it "does not validate invalid recovery code" do
96
+ FakeWeb.register_uri :get, "https://my-endpoint.dev/authful/api/users/user-authful-token/recovery_codes?code=000001111100000", {body: {error: "invalid recovery code"}.to_json, status: ["403", "invalid recovery code"]}
97
+
98
+ Authful.validate_recovery_code("user-authful-token", "000001111100000").should eq(false)
81
99
  end
82
100
 
83
101
  it "deletes users" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.16
4
+ version: 0.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Wyrosdick
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-13 00:00:00.000000000 Z
12
+ date: 2014-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client