authsignal-ruby 4.1.0 → 5.0.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -7
- data/lib/authsignal/api_error.rb +18 -6
- data/lib/authsignal/client.rb +26 -31
- data/lib/authsignal/configuration.rb +2 -2
- data/lib/authsignal/version.rb +1 -1
- data/lib/authsignal.rb +33 -27
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75bf7679eabfb897458c92a7b284ff2cdd1ea7eb833275e14c1c01c47de3ea89
|
4
|
+
data.tar.gz: 4a94529da1d514caa69e4498f68d19006a3fd09be8d094be463aa33b9bc5e4d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c12dd82892ca7c69bf2ec0e981a1ff5276e5f0fca37e6ae173ef385af63649a322b8cdc96d3e39b7d13eea7494bba97c15c234251838e092f816aed7ecaefd20
|
7
|
+
data.tar.gz: e263f4d2eaa242a23e3aafce95ea7b1db01011d33c51b45b9c655b5e184b39ddf51a4e29d2a8b5b0e6684bd2f2e8b87e110d3848819fc89dc09076bf8e4e2147
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -32,22 +32,22 @@ end
|
|
32
32
|
|
33
33
|
You can find your `api_secret_key` in the [Authsignal Portal](https://portal.authsignal.com/organisations/tenants/api).
|
34
34
|
|
35
|
-
You must specify the correct `
|
35
|
+
You must specify the correct `api_url` for your tenant's region.
|
36
36
|
|
37
|
-
| Region |
|
37
|
+
| Region | API URL |
|
38
38
|
| ----------- | ----------------------------------- |
|
39
39
|
| US (Oregon) | https://signal.authsignal.com/v1 |
|
40
40
|
| AU (Sydney) | https://au.signal.authsignal.com/v1 |
|
41
41
|
| EU (Dublin) | https://eu.signal.authsignal.com/v1 |
|
42
42
|
|
43
|
-
For example, to set the
|
43
|
+
For example, to set the API URL to use our AU region:
|
44
44
|
|
45
45
|
```
|
46
46
|
require 'authsignal'
|
47
47
|
|
48
48
|
Authsignal.setup do |config|
|
49
49
|
config.api_secret_key = ENV["AUTHSIGNAL_SECRET_KEY"]
|
50
|
-
config.
|
50
|
+
config.api_url = "https://au.signal.authsignal.com/v1"
|
51
51
|
|
52
52
|
# If you would like the Authsignal client to retry requests due to network issues
|
53
53
|
config.retry = true # default value: false
|
@@ -92,8 +92,8 @@ Authsignal.enroll_verified_authenticator user_id: 'AS_001',
|
|
92
92
|
# returns:
|
93
93
|
# {
|
94
94
|
# success?: false,
|
95
|
-
#
|
96
|
-
#
|
95
|
+
# status_code: 400,
|
96
|
+
# error_code: 'invalid_request',
|
97
97
|
# error_description: '/body/oobChannel must be equal to one of the allowed values'
|
98
98
|
# }
|
99
99
|
```
|
@@ -109,7 +109,7 @@ Authsignal.enroll_verified_authenticator! user_id: 'AS_001',
|
|
109
109
|
}
|
110
110
|
|
111
111
|
# raise:
|
112
|
-
# <Authsignal::ApiError:
|
112
|
+
# <Authsignal::ApiError: AuthsignalError: 400 - /body/oobChannel must be equal to one of the allowed values. status_code: 401, error_code: invalid_request, error_description: /body/oobChannel must be equal to one of the allowed values.
|
113
113
|
```
|
114
114
|
|
115
115
|
## Development
|
data/lib/authsignal/api_error.rb
CHANGED
@@ -2,18 +2,30 @@
|
|
2
2
|
|
3
3
|
module Authsignal
|
4
4
|
class ApiError < StandardError
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :status_code, :error_code, :error_description
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
|
9
|
-
@error = error
|
10
|
-
@description = description
|
7
|
+
def initialize(status_code, error_code, error_description = nil)
|
8
|
+
message = format_message(status_code, error_code, error_description)
|
11
9
|
|
12
10
|
super(message)
|
11
|
+
|
12
|
+
@status_code = status_code
|
13
|
+
@error_code = error_code
|
14
|
+
@error_description = error_description
|
13
15
|
end
|
14
16
|
|
15
17
|
def to_s
|
16
|
-
"#{super}
|
18
|
+
"#{super} status_code: #{status_code}, error_code: #{error_code}, error_description: #{error_description}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def format_message(status_code, error_code, error_description)
|
24
|
+
"AuthsignalError: #{status_code} - #{format_description(error_code, error_description)}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def format_description(error_code, error_description)
|
28
|
+
error_description && error_description.length > 0 ? error_description : error_code
|
17
29
|
end
|
18
30
|
end
|
19
31
|
end
|
data/lib/authsignal/client.rb
CHANGED
@@ -17,7 +17,7 @@ module Authsignal
|
|
17
17
|
@api_key = require_api_key
|
18
18
|
|
19
19
|
@client = Faraday.new do |builder|
|
20
|
-
builder.url_prefix = Authsignal.configuration.
|
20
|
+
builder.url_prefix = Authsignal.configuration.api_url
|
21
21
|
builder.adapter :net_http
|
22
22
|
builder.request :authorization, :basic, @api_key, nil
|
23
23
|
|
@@ -36,47 +36,50 @@ module Authsignal
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
39
|
+
def get_user(user_id:)
|
40
|
+
path = "users/#{url_encode(user_id)}"
|
41
|
+
make_request(:get, path)
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
def update_user(user_id:, attributes:)
|
45
|
+
make_request(:post, "users/#{url_encode(user_id)}", body: attributes)
|
46
|
+
end
|
45
47
|
|
46
|
-
|
48
|
+
def delete_user(user_id:)
|
49
|
+
make_request(:delete, "users/#{url_encode(user_id)}")
|
47
50
|
end
|
48
51
|
|
49
|
-
def
|
50
|
-
|
51
|
-
path = "users/#{url_encode(user_id)}?redirectUrl=#{redirect_url}"
|
52
|
-
else
|
53
|
-
path = "users/#{url_encode(user_id)}"
|
54
|
-
end
|
55
|
-
make_request(:get, path)
|
52
|
+
def get_authenticators(user_id:)
|
53
|
+
make_request(:get, "users/#{url_encode(user_id)}/authenticators")
|
56
54
|
end
|
57
55
|
|
58
|
-
def
|
59
|
-
make_request(:post, "users/#{url_encode(user_id)}", body:
|
56
|
+
def enroll_verified_authenticator(user_id:, attributes:)
|
57
|
+
make_request(:post, "users/#{url_encode(user_id)}/authenticators", body: attributes)
|
60
58
|
end
|
61
59
|
|
62
|
-
def
|
63
|
-
make_request(:delete, "users/#{url_encode(user_id)}")
|
60
|
+
def delete_authenticator(user_id:, user_authenticator_id:)
|
61
|
+
make_request(:delete, "users/#{url_encode(user_id)}/authenticators/#{url_encode(user_authenticator_id)}")
|
62
|
+
end
|
63
|
+
|
64
|
+
def track(user_id:, action:, attributes:)
|
65
|
+
path = "users/#{user_id}/actions/#{action}"
|
66
|
+
|
67
|
+
make_request(:post, path, body: attributes)
|
64
68
|
end
|
65
69
|
|
66
|
-
def validate_challenge(user_id: nil,
|
70
|
+
def validate_challenge(token:, user_id: nil, action: nil)
|
67
71
|
path = "validate"
|
68
72
|
body = { user_id: user_id, token: token, action: action }
|
69
73
|
|
70
74
|
make_request(:post, path, body: body)
|
71
75
|
end
|
72
76
|
|
73
|
-
def get_action(user_id
|
77
|
+
def get_action(user_id:, action:, idempotency_key:)
|
74
78
|
make_request(:get, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}")
|
75
79
|
end
|
76
80
|
|
77
|
-
def
|
78
|
-
|
79
|
-
make_request(:patch, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}", body: body)
|
81
|
+
def update_action(user_id:, action:, idempotency_key:, attributes:)
|
82
|
+
make_request(:patch, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}", body: attributes)
|
80
83
|
end
|
81
84
|
|
82
85
|
##
|
@@ -85,14 +88,6 @@ module Authsignal
|
|
85
88
|
make_request(:post , "users/#{url_encode(user_id)}", body: user_payload)
|
86
89
|
end
|
87
90
|
|
88
|
-
def enroll_verified_authenticator(user_id, authenticator)
|
89
|
-
make_request(:post, "users/#{url_encode(user_id)}/authenticators", body: authenticator)
|
90
|
-
end
|
91
|
-
|
92
|
-
def delete_authenticator(user_id:, user_authenticator_id:)
|
93
|
-
make_request(:delete, "users/#{url_encode(user_id)}/authenticators/#{url_encode(user_authenticator_id)}")
|
94
|
-
end
|
95
|
-
|
96
91
|
private
|
97
92
|
|
98
93
|
def url_encode(s)
|
@@ -13,7 +13,7 @@ module Authsignal
|
|
13
13
|
end
|
14
14
|
|
15
15
|
config_option :api_secret_key
|
16
|
-
config_option :
|
16
|
+
config_option :api_url
|
17
17
|
config_option :debug
|
18
18
|
config_option :retry
|
19
19
|
|
@@ -22,7 +22,7 @@ module Authsignal
|
|
22
22
|
|
23
23
|
# set default attribute values
|
24
24
|
@defaults = OpenStruct.new({
|
25
|
-
|
25
|
+
api_url: 'https://signal.authsignal.com/v1/',
|
26
26
|
retry: false,
|
27
27
|
debug: false
|
28
28
|
})
|
data/lib/authsignal/version.rb
CHANGED
data/lib/authsignal.rb
CHANGED
@@ -25,14 +25,14 @@ module Authsignal
|
|
25
25
|
configuration.defaults
|
26
26
|
end
|
27
27
|
|
28
|
-
def get_user(user_id
|
29
|
-
response = Client.new.get_user(user_id: user_id
|
28
|
+
def get_user(user_id:)
|
29
|
+
response = Client.new.get_user(user_id: user_id)
|
30
30
|
|
31
31
|
handle_response(response)
|
32
32
|
end
|
33
33
|
|
34
|
-
def update_user(user_id:,
|
35
|
-
response = Client.new.update_user(user_id: user_id,
|
34
|
+
def update_user(user_id:, attributes:)
|
35
|
+
response = Client.new.update_user(user_id: user_id, attributes: attributes)
|
36
36
|
|
37
37
|
handle_response(response)
|
38
38
|
end
|
@@ -43,42 +43,44 @@ module Authsignal
|
|
43
43
|
handle_response(response)
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
47
|
-
response = Client.new.
|
46
|
+
def get_authenticators(user_id:)
|
47
|
+
response = Client.new.get_authenticators(user_id: user_id)
|
48
48
|
|
49
49
|
handle_response(response)
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
|
54
|
-
response = Client.new.update_action_state(user_id: user_id, action: action, idempotency_key: idempotency_key, state: state)
|
52
|
+
def enroll_verified_authenticator(user_id:, attributes:)
|
53
|
+
response = Client.new.enroll_verified_authenticator(user_id: user_id, attributes: attributes)
|
55
54
|
|
56
55
|
handle_response(response)
|
57
56
|
end
|
58
57
|
|
59
|
-
def
|
60
|
-
response = Client.new.
|
58
|
+
def delete_authenticator(user_id:, user_authenticator_id:)
|
59
|
+
response = Client.new.delete_authenticator(user_id: user_id, user_authenticator_id: user_authenticator_id)
|
61
60
|
|
62
61
|
handle_response(response)
|
63
62
|
end
|
64
63
|
|
65
|
-
def
|
66
|
-
response = Client.new.
|
64
|
+
def track(user_id:, action:, attributes:)
|
65
|
+
response = Client.new.track(user_id: user_id, action: action, attributes: attributes)
|
66
|
+
handle_response(response)
|
67
|
+
end
|
67
68
|
|
69
|
+
def validate_challenge(token:, user_id: nil, action: nil)
|
70
|
+
response = Client.new.validate_challenge(token: token,user_id: user_id, action: action)
|
71
|
+
|
68
72
|
handle_response(response)
|
69
73
|
end
|
70
74
|
|
71
|
-
def
|
72
|
-
|
73
|
-
raise ArgumentError, "User ID value" unless event[:user_id].to_s.length > 0
|
75
|
+
def get_action(user_id:, action:, idempotency_key:)
|
76
|
+
response = Client.new.get_action(user_id: user_id, action: action, idempotency_key: idempotency_key)
|
74
77
|
|
75
|
-
response = Client.new.track(event)
|
76
78
|
handle_response(response)
|
77
79
|
end
|
78
80
|
|
79
|
-
def
|
80
|
-
response = Client.new.
|
81
|
-
|
81
|
+
def update_action(user_id:, action:, idempotency_key:, attributes:)
|
82
|
+
response = Client.new.update_action(user_id: user_id, action: action, idempotency_key: idempotency_key, attributes: attributes)
|
83
|
+
|
82
84
|
handle_response(response)
|
83
85
|
end
|
84
86
|
|
@@ -93,15 +95,19 @@ module Authsignal
|
|
93
95
|
end
|
94
96
|
|
95
97
|
def handle_success_response(response)
|
96
|
-
response.body.
|
98
|
+
if response.body.is_a?(Array)
|
99
|
+
{ success?: true, data: response.body }
|
100
|
+
else
|
101
|
+
response.body.merge(success?: true)
|
102
|
+
end
|
97
103
|
end
|
98
104
|
|
99
105
|
def handle_error_response(response)
|
100
106
|
case response.body
|
101
107
|
when Hash
|
102
|
-
|
108
|
+
{ status_code: response.status, success?: false, error_code: response.body[:error], error_description: response.body[:error_description] }
|
103
109
|
else
|
104
|
-
{
|
110
|
+
{ status_code: response&.status || 500, success?: false }
|
105
111
|
end
|
106
112
|
end
|
107
113
|
end
|
@@ -110,11 +116,11 @@ module Authsignal
|
|
110
116
|
(methods - NON_API_METHODS).each do |method|
|
111
117
|
define_singleton_method("#{method}!") do |*args, **kwargs|
|
112
118
|
send(method, *args, **kwargs).tap do |response|
|
113
|
-
|
114
|
-
|
115
|
-
|
119
|
+
status_code = response[:status_code]
|
120
|
+
error_code = response[:error_code]
|
121
|
+
error_description = response[:error_description]
|
116
122
|
|
117
|
-
raise ApiError.new(
|
123
|
+
raise ApiError.new(status_code, error_code, error_description) unless response[:success?]
|
118
124
|
end
|
119
125
|
end
|
120
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authsignal-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- justinsoong
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
rubygems_version: 3.5.
|
130
|
+
rubygems_version: 3.5.22
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: The Authsignal ruby server side signal API.
|