authy 2.0.1 → 2.1.0
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.
- data/Gemfile.lock +25 -25
- data/README.md +50 -6
- data/VERSION +1 -1
- data/authy.gemspec +2 -2
- data/lib/authy/api.rb +24 -1
- data/spec/authy/api_spec.rb +51 -21
- metadata +11 -11
data/Gemfile.lock
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
coderay (1.0.
|
5
|
-
diff-lcs (1.
|
4
|
+
coderay (1.0.9)
|
5
|
+
diff-lcs (1.2.4)
|
6
6
|
git (1.2.5)
|
7
|
-
httpclient (2.3.
|
7
|
+
httpclient (2.3.3)
|
8
8
|
jeweler (1.8.4)
|
9
9
|
bundler (~> 1.0)
|
10
10
|
git (>= 1.2.5)
|
11
11
|
rake
|
12
12
|
rdoc
|
13
|
-
json (1.
|
13
|
+
json (1.8.0)
|
14
14
|
method_source (0.8.1)
|
15
|
-
multi_json (1.5
|
16
|
-
pry (0.9.
|
15
|
+
multi_json (1.7.5)
|
16
|
+
pry (0.9.12.2)
|
17
17
|
coderay (~> 1.0.5)
|
18
18
|
method_source (~> 0.8)
|
19
19
|
slop (~> 3.4)
|
20
|
-
rake (10.0.
|
21
|
-
rdoc (
|
20
|
+
rake (10.0.4)
|
21
|
+
rdoc (4.0.1)
|
22
22
|
json (~> 1.4)
|
23
|
-
reek (1.3)
|
24
|
-
ruby2ruby (~> 2.0.
|
25
|
-
ruby_parser (~> 3.
|
23
|
+
reek (1.3.1)
|
24
|
+
ruby2ruby (~> 2.0.2)
|
25
|
+
ruby_parser (~> 3.1.1)
|
26
26
|
sexp_processor
|
27
|
-
rspec (2.
|
28
|
-
rspec-core (~> 2.
|
29
|
-
rspec-expectations (~> 2.
|
30
|
-
rspec-mocks (~> 2.
|
31
|
-
rspec-core (2.
|
32
|
-
rspec-expectations (2.
|
33
|
-
diff-lcs (
|
34
|
-
rspec-mocks (2.
|
35
|
-
ruby2ruby (2.0.
|
36
|
-
ruby_parser (~> 3.
|
27
|
+
rspec (2.13.0)
|
28
|
+
rspec-core (~> 2.13.0)
|
29
|
+
rspec-expectations (~> 2.13.0)
|
30
|
+
rspec-mocks (~> 2.13.0)
|
31
|
+
rspec-core (2.13.1)
|
32
|
+
rspec-expectations (2.13.0)
|
33
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
34
|
+
rspec-mocks (2.13.1)
|
35
|
+
ruby2ruby (2.0.5)
|
36
|
+
ruby_parser (~> 3.1)
|
37
37
|
sexp_processor (~> 4.0)
|
38
|
-
ruby_parser (3.
|
38
|
+
ruby_parser (3.1.3)
|
39
39
|
sexp_processor (~> 4.1)
|
40
|
-
sexp_processor (4.1
|
40
|
+
sexp_processor (4.2.1)
|
41
41
|
simplecov (0.7.1)
|
42
42
|
multi_json (~> 1.0)
|
43
43
|
simplecov-html (~> 0.7.1)
|
44
44
|
simplecov-html (0.7.1)
|
45
|
-
slop (3.4.
|
46
|
-
yard (0.8.
|
45
|
+
slop (3.4.5)
|
46
|
+
yard (0.8.6.1)
|
47
47
|
|
48
48
|
PLATFORMS
|
49
49
|
ruby
|
data/README.md
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
# Authy
|
1
|
+
# Authy [](https://travis-ci.org/authy/authy-ruby) [](https://codeclimate.com/github/authy/authy-ruby)
|
2
2
|
|
3
3
|
Ruby library to access the Authy API
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
+
```ruby
|
7
8
|
require 'authy'
|
8
9
|
|
9
10
|
Authy.api_key = 'your-api-key'
|
10
11
|
Authy.api_uri = 'https://api.authy.com/'
|
11
|
-
|
12
|
+
```
|
12
13
|
|
13
14
|
## Registering a user
|
14
15
|
|
@@ -21,6 +22,7 @@ USA. The call will return you the authy id for the user that you need to store i
|
|
21
22
|
|
22
23
|
Assuming you have a `users` database with a `authy_id` field in the `users` database.
|
23
24
|
|
25
|
+
```ruby
|
24
26
|
authy = Authy::API.register_user(:email => 'users@email.com', :cellphone => "111-111-1111", :country_code => "1")
|
25
27
|
|
26
28
|
if authy.ok?
|
@@ -28,7 +30,7 @@ Assuming you have a `users` database with a `authy_id` field in the `users` data
|
|
28
30
|
else
|
29
31
|
authy.errors # this will return an error hash
|
30
32
|
end
|
31
|
-
|
33
|
+
```
|
32
34
|
|
33
35
|
## Verifying a user
|
34
36
|
|
@@ -39,6 +41,7 @@ __NOTE: Token verification is only enforced if the user has completed registrati
|
|
39
41
|
|
40
42
|
`Authy::API.verify` takes the authy_id that you are verifying and the token that you want to verify. You should have the authy_id in your database
|
41
43
|
|
44
|
+
```ruby
|
42
45
|
response = Authy::API.verify(:id => user.authy_id, :token => 'token-user-entered')
|
43
46
|
|
44
47
|
if response.ok?
|
@@ -46,17 +49,21 @@ __NOTE: Token verification is only enforced if the user has completed registrati
|
|
46
49
|
else
|
47
50
|
# token is invalid
|
48
51
|
end
|
49
|
-
|
52
|
+
```
|
53
|
+
|
50
54
|
### Forcing Verification
|
51
55
|
|
52
56
|
If you wish to verify tokens even if the user has not yet complete registration, pass force=true when verifying the token.
|
53
57
|
|
58
|
+
```ruby
|
54
59
|
response = Authy::API.verify(:id => user.authy_id, :token => 'token-user-entered', :force => true)
|
55
|
-
|
60
|
+
```
|
61
|
+
|
56
62
|
## Requesting a SMS token
|
57
63
|
|
58
64
|
`Authy::API.request_sms` takes the authy_id that you want to send a SMS token. This requires Authy SMS plugin to be enabled.
|
59
65
|
|
66
|
+
```ruby
|
60
67
|
response = Authy::API.request_sms(:id => user.authy_id)
|
61
68
|
|
62
69
|
if response.ok?
|
@@ -65,13 +72,50 @@ If you wish to verify tokens even if the user has not yet complete registration,
|
|
65
72
|
response.errors
|
66
73
|
#sms failed to send
|
67
74
|
end
|
68
|
-
|
75
|
+
```
|
69
76
|
|
70
77
|
This call will be ignored if the user is using the Authy Mobile App. If you still want to send
|
71
78
|
the SMS pass force=true as an option
|
72
79
|
|
80
|
+
```ruby
|
73
81
|
response = Authy::API.request_sms(:id => user.authy_id, :force => true)
|
82
|
+
```
|
83
|
+
|
84
|
+
## Requesting token via a phone call
|
85
|
+
|
86
|
+
`Authy::API.request_phone_call` takes the authy_id that you want to deliver the token by a phone call. This requires Authy Calls addon, please contact us to support@authy.com to enable this addon.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
response = Authy::API.request_phone_call(:id => user.authy_id)
|
90
|
+
|
91
|
+
if response.ok?
|
92
|
+
# call was done
|
93
|
+
else
|
94
|
+
response.errors
|
95
|
+
# call failed
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
This call will be ignored if the user is using the Authy Mobile App. If you ensure that user receives the phone call, you must pass force=true as an option
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
response = Authy::API.request_phone_call(:id => user.authy_id, :force => true)
|
103
|
+
```
|
104
|
+
|
105
|
+
## Deleting users
|
106
|
+
|
107
|
+
`Authy::API.delete_user` takes the authy_id of the user that you want to remove from your app.
|
74
108
|
|
109
|
+
```ruby
|
110
|
+
response = Authy::API.delete_user(:id => user.authy_id)
|
111
|
+
|
112
|
+
if response.ok?
|
113
|
+
# the user was deleted
|
114
|
+
else
|
115
|
+
response.errors
|
116
|
+
# we were unavailable to delete the user
|
117
|
+
end
|
118
|
+
```
|
75
119
|
|
76
120
|
### Contributing to authy
|
77
121
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0
|
1
|
+
2.1.0
|
data/authy.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "authy"
|
8
|
-
s.version = "2.0
|
8
|
+
s.version = "2.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Authy", "David A. Cuadrado"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-06-03"
|
13
13
|
s.description = "Ruby library to access Authy services"
|
14
14
|
s.email = "krawek@gmail.com"
|
15
15
|
s.executables = ["authy-api-console"]
|
data/lib/authy/api.rb
CHANGED
@@ -50,11 +50,34 @@ module Authy
|
|
50
50
|
Authy::Response.new(response)
|
51
51
|
end
|
52
52
|
|
53
|
+
# options:
|
54
|
+
# :id user id
|
55
|
+
# :force force phone_call
|
56
|
+
def self.request_phone_call(params)
|
57
|
+
user_id = params.delete(:id) || params.delete('id')
|
58
|
+
|
59
|
+
url = "#{Authy.api_uri}/protected/json/call/#{escape_for_url(user_id)}"
|
60
|
+
response = http_client.get(url, {:api_key => Authy.api_key}.merge(params))
|
61
|
+
|
62
|
+
Authy::Response.new(response)
|
63
|
+
end
|
64
|
+
|
65
|
+
# options:
|
66
|
+
# :id user id
|
67
|
+
def self.delete_user(params)
|
68
|
+
user_id = params.delete(:id) || params.delete('id')
|
69
|
+
|
70
|
+
url = "#{Authy.api_uri}/protected/json/users/delete/#{escape_for_url(user_id)}"
|
71
|
+
response = http_client.post(url, {:api_key => Authy.api_key}.merge(params))
|
72
|
+
|
73
|
+
Authy::Response.new(response)
|
74
|
+
end
|
75
|
+
|
53
76
|
private
|
54
77
|
def self.escape_for_url(field)
|
55
78
|
URI.escape(field.to_s.strip, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
56
79
|
end
|
57
|
-
|
80
|
+
|
58
81
|
# Copied and extended from httpclient's HTTP::Message#escape_query()
|
59
82
|
def self.escape_query(query, namespace = nil) # :nodoc:
|
60
83
|
pairs = []
|
data/spec/authy/api_spec.rb
CHANGED
@@ -14,7 +14,7 @@ describe "Authy::API" do
|
|
14
14
|
user.id.should_not be_nil
|
15
15
|
user.id.should be_kind_of(Integer)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should return the error messages as a hash" do
|
19
19
|
user = Authy::API.register_user(:email => generate_email,
|
20
20
|
:cellphone => "abc-1234",
|
@@ -43,20 +43,12 @@ describe "Authy::API" do
|
|
43
43
|
@user.should be_ok
|
44
44
|
end
|
45
45
|
|
46
|
-
#it "should validate a given token if the user is not registered when the verification is not forced" do
|
47
|
-
#pending "Sandbox api always auto-confirm all users so there's no way check this atm"
|
48
|
-
#response = Authy::API.verify(:token => 'invalid_token', :id => @user['id'], :force => false)
|
49
|
-
|
50
|
-
#response.should be_kind_of(Authy::Response)
|
51
|
-
#response.ok?.should be_true
|
52
|
-
#end
|
53
|
-
|
54
46
|
it "should fail to validate a given token if the user is not registered" do
|
55
47
|
response = Authy::API.verify(:token => 'invalid_token', :id => @user['id'])
|
56
48
|
|
57
49
|
response.should be_kind_of(Authy::Response)
|
58
50
|
response.ok?.should be_false
|
59
|
-
response.errors['
|
51
|
+
response.errors['message'].should == 'token is invalid'
|
60
52
|
end
|
61
53
|
|
62
54
|
it "should allow to override the API key" do
|
@@ -67,21 +59,59 @@ describe "Authy::API" do
|
|
67
59
|
end
|
68
60
|
end
|
69
61
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
62
|
+
["sms", "phone_call"].each do |kind|
|
63
|
+
title = kind.upcase
|
64
|
+
describe "Requesting #{title}" do
|
65
|
+
before do
|
66
|
+
@user = Authy::API.register_user(:email => generate_email, :cellphone => generate_cellphone, :country_code => 1)
|
67
|
+
@user.should be_ok
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should request a #{title} token" do
|
71
|
+
uri_param = kind == "phone_call" ? "call" : kind
|
72
|
+
url = "#{Authy.api_uri}/protected/json/#{uri_param}/#{Authy::API.escape_for_url(@user.id)}"
|
73
|
+
HTTPClient.any_instance.should_receive(:request).with(:get, url, {:query=>{:api_key=> Authy.api_key}, :header=>nil, :follow_redirect=>nil}) { mock(:ok? => true, :body => "", :status => 200) }
|
74
|
+
response = Authy::API.send("request_#{kind}", :id => @user.id)
|
75
|
+
response.should be_ok
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should allow to override the API key" do
|
79
|
+
response = Authy::API.send("request_#{kind}", :id => @user.id, :api_key => "invalid_api_key")
|
80
|
+
response.should_not be_ok
|
81
|
+
response.errors['message'].should =~ /invalid api key/i
|
82
|
+
end
|
83
|
+
|
84
|
+
context "user doesn't exist" do
|
85
|
+
it "should not be ok" do
|
86
|
+
response = Authy::API.send("request_#{kind}", :id => "tony")
|
87
|
+
response.errors['message'].should == "User doesn't exist."
|
88
|
+
response.should_not be_ok
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
74
92
|
end
|
93
|
+
end
|
75
94
|
|
76
|
-
|
77
|
-
|
78
|
-
|
95
|
+
describe "delete users" do
|
96
|
+
context "user doesn't exist" do
|
97
|
+
it "should not be ok" do
|
98
|
+
response = Authy::API.delete_user(:id => "tony")
|
99
|
+
response.errors['message'].should == "User doesn't exist."
|
100
|
+
response.should_not be_ok
|
101
|
+
end
|
79
102
|
end
|
80
103
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
104
|
+
context "user exists" do
|
105
|
+
before do
|
106
|
+
@user = Authy::API.register_user(:email => generate_email, :cellphone => generate_cellphone, :country_code => 1)
|
107
|
+
@user.should be_ok
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should be ok" do
|
111
|
+
response = Authy::API.delete_user(:id => @user.id)
|
112
|
+
response.message.should == "User was added to remove."
|
113
|
+
response.should be_ok
|
114
|
+
end
|
85
115
|
end
|
86
116
|
end
|
87
117
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: authy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.0
|
5
|
+
version: 2.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Authy
|
@@ -10,10 +10,9 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
type: :runtime
|
17
16
|
version_requirements: !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
@@ -21,6 +20,7 @@ dependencies:
|
|
21
20
|
- !ruby/object:Gem::Version
|
22
21
|
version: 2.2.6
|
23
22
|
name: httpclient
|
23
|
+
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
requirement: !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
@@ -29,7 +29,6 @@ dependencies:
|
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: 2.2.6
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
|
-
type: :development
|
33
32
|
version_requirements: !ruby/object:Gem::Requirement
|
34
33
|
none: false
|
35
34
|
requirements:
|
@@ -37,6 +36,7 @@ dependencies:
|
|
37
36
|
- !ruby/object:Gem::Version
|
38
37
|
version: '0'
|
39
38
|
name: rspec
|
39
|
+
type: :development
|
40
40
|
prerelease: false
|
41
41
|
requirement: !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
@@ -45,7 +45,6 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
type: :development
|
49
48
|
version_requirements: !ruby/object:Gem::Requirement
|
50
49
|
none: false
|
51
50
|
requirements:
|
@@ -53,6 +52,7 @@ dependencies:
|
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: '0'
|
55
54
|
name: pry
|
55
|
+
type: :development
|
56
56
|
prerelease: false
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
@@ -61,7 +61,6 @@ dependencies:
|
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
|
-
type: :development
|
65
64
|
version_requirements: !ruby/object:Gem::Requirement
|
66
65
|
none: false
|
67
66
|
requirements:
|
@@ -69,6 +68,7 @@ dependencies:
|
|
69
68
|
- !ruby/object:Gem::Version
|
70
69
|
version: '0'
|
71
70
|
name: yard
|
71
|
+
type: :development
|
72
72
|
prerelease: false
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
@@ -77,7 +77,6 @@ dependencies:
|
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
|
-
type: :development
|
81
80
|
version_requirements: !ruby/object:Gem::Requirement
|
82
81
|
none: false
|
83
82
|
requirements:
|
@@ -85,6 +84,7 @@ dependencies:
|
|
85
84
|
- !ruby/object:Gem::Version
|
86
85
|
version: '0'
|
87
86
|
name: rdoc
|
87
|
+
type: :development
|
88
88
|
prerelease: false
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
90
90
|
none: false
|
@@ -93,7 +93,6 @@ dependencies:
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
|
-
type: :development
|
97
96
|
version_requirements: !ruby/object:Gem::Requirement
|
98
97
|
none: false
|
99
98
|
requirements:
|
@@ -101,6 +100,7 @@ dependencies:
|
|
101
100
|
- !ruby/object:Gem::Version
|
102
101
|
version: '0'
|
103
102
|
name: jeweler
|
103
|
+
type: :development
|
104
104
|
prerelease: false
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
@@ -109,7 +109,6 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
type: :development
|
113
112
|
version_requirements: !ruby/object:Gem::Requirement
|
114
113
|
none: false
|
115
114
|
requirements:
|
@@ -117,6 +116,7 @@ dependencies:
|
|
117
116
|
- !ruby/object:Gem::Version
|
118
117
|
version: '0'
|
119
118
|
name: simplecov
|
119
|
+
type: :development
|
120
120
|
prerelease: false
|
121
121
|
requirement: !ruby/object:Gem::Requirement
|
122
122
|
none: false
|
@@ -125,7 +125,6 @@ dependencies:
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
|
-
type: :development
|
129
128
|
version_requirements: !ruby/object:Gem::Requirement
|
130
129
|
none: false
|
131
130
|
requirements:
|
@@ -133,6 +132,7 @@ dependencies:
|
|
133
132
|
- !ruby/object:Gem::Version
|
134
133
|
version: '0'
|
135
134
|
name: reek
|
135
|
+
type: :development
|
136
136
|
prerelease: false
|
137
137
|
requirement: !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
@@ -183,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
183
|
- !ruby/object:Gem::Version
|
184
184
|
segments:
|
185
185
|
- 0
|
186
|
-
hash:
|
186
|
+
hash: 1227098339926430603
|
187
187
|
version: '0'
|
188
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
189
|
none: false
|