trusona 0.16.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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.env.example +4 -0
- data/.gitignore +20 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +24 -0
- data/Gemfile +8 -0
- data/Guardfile +54 -0
- data/LICENSE +201 -0
- data/README.md +234 -0
- data/Rakefile +8 -0
- data/bin/console +21 -0
- data/bin/setup +8 -0
- data/certs/trusona.pem +26 -0
- data/checksum/trusona-0.16.0.gem.sha512 +1 -0
- data/integrations/device_user_binding_integration_spec.rb +6 -0
- data/integrations/identity_documents_spec.rb +28 -0
- data/integrations/spec_helper.rb +23 -0
- data/integrations/tru_code_spec.rb +80 -0
- data/integrations/trusonafication_spec.rb +61 -0
- data/integrations/user_accounts_spec.rb +39 -0
- data/integrations/user_identifiers_spec.rb +32 -0
- data/lib/trusona.rb +157 -0
- data/lib/trusona/api/client.rb +60 -0
- data/lib/trusona/api/hashed_message.rb +71 -0
- data/lib/trusona/api/signed_request.rb +96 -0
- data/lib/trusona/api/verified_response.rb +85 -0
- data/lib/trusona/device.rb +31 -0
- data/lib/trusona/device_user_binding.rb +56 -0
- data/lib/trusona/errors.rb +51 -0
- data/lib/trusona/helpers/key_normalizer.rb +15 -0
- data/lib/trusona/helpers/time_normalizer.rb +17 -0
- data/lib/trusona/identity_document.rb +64 -0
- data/lib/trusona/mappers/base_mapper.rb +69 -0
- data/lib/trusona/mappers/device_mapper.rb +13 -0
- data/lib/trusona/mappers/device_user_binding_mapper.rb +13 -0
- data/lib/trusona/mappers/identity_document_mapper.rb +17 -0
- data/lib/trusona/mappers/nil_mapper.rb +11 -0
- data/lib/trusona/mappers/tru_code_mapper.rb +13 -0
- data/lib/trusona/mappers/trusonafication_mapper.rb +19 -0
- data/lib/trusona/mappers/user_account_mapper.rb +13 -0
- data/lib/trusona/mappers/user_identifier_mapper.rb +13 -0
- data/lib/trusona/resources/base_resource.rb +29 -0
- data/lib/trusona/resources/device.rb +22 -0
- data/lib/trusona/resources/device_user_binding.rb +30 -0
- data/lib/trusona/resources/device_user_binding_activation.rb +27 -0
- data/lib/trusona/resources/identity_document.rb +36 -0
- data/lib/trusona/resources/tru_code.rb +42 -0
- data/lib/trusona/resources/trusonafication.rb +137 -0
- data/lib/trusona/resources/user_account.rb +84 -0
- data/lib/trusona/resources/user_identifier.rb +49 -0
- data/lib/trusona/resources/validators.rb +22 -0
- data/lib/trusona/services/account_lookups_service.rb +17 -0
- data/lib/trusona/services/base_service.rb +117 -0
- data/lib/trusona/services/device_user_bindings_service.rb +22 -0
- data/lib/trusona/services/devices_service.rb +15 -0
- data/lib/trusona/services/identity_documents_service.rb +31 -0
- data/lib/trusona/services/tru_codes_service.rb +26 -0
- data/lib/trusona/services/trusonafication_service.rb +16 -0
- data/lib/trusona/services/user_accounts_service.rb +17 -0
- data/lib/trusona/services/user_identifiers_service.rb +16 -0
- data/lib/trusona/tru_code.rb +38 -0
- data/lib/trusona/tru_code_config.rb +45 -0
- data/lib/trusona/trusonafication.rb +133 -0
- data/lib/trusona/user_account.rb +17 -0
- data/lib/trusona/user_identifier.rb +15 -0
- data/lib/trusona/version.rb +5 -0
- data/lib/trusona/workers/device_finder.rb +18 -0
- data/lib/trusona/workers/device_user_binding_activator.rb +25 -0
- data/lib/trusona/workers/device_user_binding_creator.rb +26 -0
- data/lib/trusona/workers/identity_document_finder.rb +25 -0
- data/lib/trusona/workers/tru_code_creator.rb +17 -0
- data/lib/trusona/workers/tru_code_finder.rb +19 -0
- data/lib/trusona/workers/trusonafication_creator.rb +46 -0
- data/lib/trusona/workers/trusonafication_finder.rb +27 -0
- data/lib/trusona/workers/user_account_finder.rb +39 -0
- data/lib/trusona/workers/user_identifier_creator.rb +17 -0
- data/lib/trusona/workers/user_identifier_finder.rb +29 -0
- data/release-gem +17 -0
- data/trusona.gemspec +43 -0
- metadata +333 -0
- metadata.gz.sig +1 -0
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'dotenv'
|
5
|
+
Dotenv.load
|
6
|
+
require 'bundler/setup'
|
7
|
+
require 'trusona'
|
8
|
+
|
9
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
10
|
+
# with your gem easier. You can also use a different console, if you like.
|
11
|
+
|
12
|
+
Trusona.config do |c|
|
13
|
+
c.beacons_host = ENV['BEACONS_HOST']
|
14
|
+
c.api_host = ENV['TRUSONA_API_HOST']
|
15
|
+
c.secret = ENV['TRUSONA_SECRET']
|
16
|
+
c.token = ENV['TRUSONA_TOKEN']
|
17
|
+
end
|
18
|
+
|
19
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
20
|
+
require 'pry'
|
21
|
+
Pry.start
|
data/bin/setup
ADDED
data/certs/trusona.pem
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIETTCCArWgAwIBAgIBATANBgkqhkiG9w0BAQsFADAoMSYwJAYDVQQDDB1lbmdp
|
3
|
+
bmVlcmluZy9EQz10cnVzb25hL0RDPWNvbTAeFw0xODA3MDUxNjQyNTVaFw0xOTA3
|
4
|
+
MDUxNjQyNTVaMCgxJjAkBgNVBAMMHWVuZ2luZWVyaW5nL0RDPXRydXNvbmEvREM9
|
5
|
+
Y29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAtZt82g/ZeiJshGdi
|
6
|
+
twfXgueVDyMEsV+h7mRwDqOhwwwJ9/EBwu2Ma56LQHKMqDsVaSljTUo4WNSm9M7r
|
7
|
+
H6c/IW6O07X/2YA29jwUveauKjkBmmEpECr7hTe0UHoOm9jV5DHeoBsgpMSFqC3C
|
8
|
+
myBP8ik/A+xEQPo8F43TMX2YP3EFQw8ievUdCvwgjapFoyFoBlmrbfHMyYH1XTfF
|
9
|
+
hth9YAZoYYSaVHKYleEWz73ZPZyYqXUm2G56eAOAu6+Ghi3G9F2FtxwGVpjAnKc6
|
10
|
+
r37RRWG5b6Sfuj9ojds9sn8EExUTroti5Jb6RpJI54+IKuarfEe7ygn6PBsianbF
|
11
|
+
b9FJ/PQgUNOrCkEum8iBrJW2eBgNKsC39kX7luUeot6aBpO16E8exrNwia7aWVn1
|
12
|
+
lOW2DpjLWpyQDC3iCmV5JZD3Ffg1uGaMg1ln1BAtLH9StDqi8EPL3lmXQM2uvi9f
|
13
|
+
KXCrw0eSiDGD1PUdKJ0RE/hByKLtGn7UygIKsV8v7R/L+PwNAgMBAAGjgYEwfzAJ
|
14
|
+
BgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU82ZI29Yn4SX0EuOrfvkc
|
15
|
+
Fs2cy2wwIgYDVR0RBBswGYEXZW5naW5lZXJpbmdAdHJ1c29uYS5jb20wIgYDVR0S
|
16
|
+
BBswGYEXZW5naW5lZXJpbmdAdHJ1c29uYS5jb20wDQYJKoZIhvcNAQELBQADggGB
|
17
|
+
AC3rcLcSs4JCMfVNJxx2ugAqxagKV9Hbpl9hLMDCv2M4rc4kWKwuSyihhaetq+2U
|
18
|
+
hzWaqX0yUzBC1KCOxuZOxpC0KscsYGeLiGRILZetUl6Kj/4H/Xjaj1gkW4mtCfeh
|
19
|
+
5QC/1FM/C3AExN5oWNQUTBQ2XFain5RxR/SJVidJt+6DOePhqY2zAp7lweIIcjit
|
20
|
+
bJNU+hSx7iO750Wnn969yQDRNKnNIULAmpvgGpErv8kx5FELDypEZtRWK4wmPkyz
|
21
|
+
vDcXXHq4276Zr5idZbx/uxeRuS05rL+o/LmN1KNvxxJCoqAv+meGhMQ645WKs5La
|
22
|
+
oeFOElmMyJfOJcYAp5KP5Rvn/llhVYYaGtOsoY7+6U0fN0DzucZmtfwtp4r9foVY
|
23
|
+
5dMuMQ9V7c0EWtZm8J+tcQh9dPPC4Va/FnYWw+x6CDmVU/nijUAI1UOxSSuekJXb
|
24
|
+
vbhUT8kOS+bZTalorEol37DD/P4Bbv0fMpw+ozetR2RmwhwTKPKJ5r0oQP6tiqHn
|
25
|
+
hQ==
|
26
|
+
-----END CERTIFICATE-----
|
@@ -0,0 +1 @@
|
|
1
|
+
236cc89e2bd9c15c00c2f1b3d31d6b82fda85e46bcd3ea615ca3461020b3f56a889fdfbd0bdd2b2e3cc2e48aa92e0bebfdd8f373d59a0a72126efe0c2d8bbc08
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'Identity Documents' do
|
6
|
+
before do
|
7
|
+
Trusona.config do |c|
|
8
|
+
c.tru_codes_host = ENV['TRUCODES_HOST']
|
9
|
+
c.api_host = ENV['TRUSONA_API_HOST']
|
10
|
+
c.secret = ENV['TRUSONA_SECRET']
|
11
|
+
c.token = ENV['TRUSONA_TOKEN']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'finding all documents for a user identifier' do
|
16
|
+
it 'should work' do
|
17
|
+
result = Trusona::IdentityDocument.all(user_identifier: SecureRandom.uuid)
|
18
|
+
expect(result).to eq([])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'finding a single identity document' do
|
23
|
+
it 'should work' do
|
24
|
+
result = Trusona::IdentityDocument.find(id: SecureRandom.uuid)
|
25
|
+
expect(result).to eq(nil)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dotenv/load'
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter '/spec/'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'bundler/setup'
|
10
|
+
require 'trusona'
|
11
|
+
require 'securerandom'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
# Enable flags like --only-failures and --next-failure
|
15
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
16
|
+
|
17
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
18
|
+
config.disable_monkey_patching!
|
19
|
+
|
20
|
+
config.expect_with :rspec do |c|
|
21
|
+
c.syntax = :expect
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal:true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
# rubocop:disable Metrics/BlockLength
|
7
|
+
RSpec.describe 'TruCodes' do
|
8
|
+
before do
|
9
|
+
Trusona.config do |c|
|
10
|
+
c.tru_codes_host = ENV['TRUCODES_HOST']
|
11
|
+
c.api_host = ENV['TRUSONA_API_HOST']
|
12
|
+
c.secret = ENV['TRUSONA_SECRET']
|
13
|
+
c.token = ENV['TRUSONA_TOKEN']
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'creating a TruCode to show on your website' do
|
18
|
+
before do
|
19
|
+
@reference_id = SecureRandom.uuid
|
20
|
+
end
|
21
|
+
it 'just works' do
|
22
|
+
code = Trusona::Resources::TruCode.new(
|
23
|
+
reference_id: @reference_id,
|
24
|
+
action: 'verify',
|
25
|
+
resource: 'integration-test',
|
26
|
+
level: 1
|
27
|
+
)
|
28
|
+
|
29
|
+
result = Trusona::TruCode.create(code)
|
30
|
+
|
31
|
+
expect(result.tru_code).to be
|
32
|
+
expect(result.signature).to be
|
33
|
+
expect(result.relying_party_id).to be
|
34
|
+
expect(result.tru_code).to be
|
35
|
+
expect(result.tru_code.id).to be
|
36
|
+
expect(result.tru_code.payload).to be
|
37
|
+
expect(result.tru_code.image).to be
|
38
|
+
expect(result.tru_code.id).to be
|
39
|
+
expect(result.tru_code.reference_id).to eq(@reference_id)
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'and when you want to check the status of that TruCode' do
|
43
|
+
before do
|
44
|
+
@qr = Tempfile.new('tru_code')
|
45
|
+
code = Trusona::Resources::TruCode.new(
|
46
|
+
reference_id: @reference_id,
|
47
|
+
action: 'verify',
|
48
|
+
resource: 'integration-test',
|
49
|
+
level: 1
|
50
|
+
)
|
51
|
+
|
52
|
+
@created = Trusona::TruCode.create(code)
|
53
|
+
end
|
54
|
+
|
55
|
+
after do
|
56
|
+
@qr.close
|
57
|
+
@qr.unlink
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'can be checked by using the tru code resource' do
|
61
|
+
expect { Trusona::TruCode.status(@created) }.to(
|
62
|
+
raise_error(Trusona::ResourceNotFoundError)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'can be checked by using the tru_code resource' do
|
67
|
+
expect { Trusona::TruCode.status(@created.tru_code) }.to(
|
68
|
+
raise_error(Trusona::ResourceNotFoundError)
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'can be checked by using the tru_code id' do
|
73
|
+
expect { Trusona::TruCode.status(tru_code_id: @created.tru_code.id) }.to(
|
74
|
+
raise_error(Trusona::ResourceNotFoundError)
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
# rubocop:enable Metrics/BlockLength
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# rubocop:disable Metrics/BlockLength
|
6
|
+
RSpec.describe 'Trusonafications' do
|
7
|
+
before do
|
8
|
+
Trusona.config do |c|
|
9
|
+
c.tru_codes_host = ENV['TRUCODES_HOST']
|
10
|
+
c.api_host = ENV['TRUSONA_API_HOST']
|
11
|
+
c.secret = ENV['TRUSONA_SECRET']
|
12
|
+
c.token = ENV['TRUSONA_TOKEN']
|
13
|
+
end
|
14
|
+
|
15
|
+
@parameters = {
|
16
|
+
resource: 'integration test suite',
|
17
|
+
action: 'verify',
|
18
|
+
user_identifier: 'claytonhauz@gmail.com'
|
19
|
+
}
|
20
|
+
|
21
|
+
@timeout = 5
|
22
|
+
end
|
23
|
+
describe 'creating a trusonafication for a known trusona user' do
|
24
|
+
before do
|
25
|
+
@trusonafication = Trusona::EssentialTrusonafication.create(
|
26
|
+
params: @parameters, timeout: @timeout
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'just works' do
|
31
|
+
expect(@trusonafication.status).to eq(:in_progress)
|
32
|
+
expect(@trusonafication.user_identifier).to eq('claytonhauz@gmail.com')
|
33
|
+
expect(@trusonafication.resource).to eq('integration test suite')
|
34
|
+
expect(@trusonafication.action).to eq('verify')
|
35
|
+
expect(@trusonafication.level).to eq(2)
|
36
|
+
expect(@trusonafication.expires_at).to be
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'and when you try to find that same trusonafication' do
|
40
|
+
it 'that just works too' do
|
41
|
+
@found = Trusona::Trusonafication.find(@trusonafication.id)
|
42
|
+
expect(@found.trusona_id).to eq(@trusonafication.trusona_id)
|
43
|
+
expect(@found.status).to eq(@trusonafication.status)
|
44
|
+
expect(@found.resource).to eq(@trusonafication.resource)
|
45
|
+
expect(@found.action).to eq(@trusonafication.action)
|
46
|
+
expect(@found.level).to eq(@trusonafication.level)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
describe 'creating a trusonafication for an unknown trusona user' do
|
51
|
+
it 'as expected, does not work' do
|
52
|
+
@parameters[:user_identifier] = "#{Time.now.to_i}@example.com"
|
53
|
+
trusonafication = Trusona::Trusonafication.create(
|
54
|
+
params: @parameters, timeout: @timeout
|
55
|
+
)
|
56
|
+
|
57
|
+
expect(trusonafication.trusona_id).to_not be
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
# rubocop:enable Metrics/BlockLength
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# rubocop:disable Metrics/BlockLength
|
6
|
+
RSpec.describe 'Trusona User Accounts' do
|
7
|
+
before do
|
8
|
+
Trusona.config do |c|
|
9
|
+
c.tru_codes_host = ENV['TRUCODES_HOST']
|
10
|
+
c.api_host = ENV['TRUSONA_API_HOST']
|
11
|
+
c.secret = ENV['TRUSONA_SECRET']
|
12
|
+
c.token = ENV['TRUSONA_TOKEN']
|
13
|
+
end
|
14
|
+
|
15
|
+
@account_lookup = { trusona_id: '167791378' }
|
16
|
+
@email_lookup = { email: 'claytonhauz@gmail.com' }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'retrieving a user account with their Trusona ID' do
|
20
|
+
context 'when the user account exists and can be found' do
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when no user account exists for the given Trusona ID' do
|
24
|
+
it 'then we should see a Trusona::ResourceNotFound error raised' do
|
25
|
+
expect { Trusona::UserAccounts.find_by(@account_lookup) }.to(
|
26
|
+
raise_error(Trusona::ResourceNotFoundError)
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'searching for a user account using their email' do
|
33
|
+
context 'when a user account exists with the given email' do
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when no user accounts exist with the given email' do
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe 'Trusona User Identifiers' do
|
6
|
+
before do
|
7
|
+
Trusona.config do |c|
|
8
|
+
c.api_host = ENV['TRUSONA_API_HOST']
|
9
|
+
c.secret = ENV['TRUSONA_SECRET']
|
10
|
+
c.token = ENV['TRUSONA_TOKEN']
|
11
|
+
end
|
12
|
+
|
13
|
+
@identifier = Trusona::Resources::UserIdentifier.new(identifier: 'am9uZXNAdGFjb3MubmV0Cg==', trusona_id: '264683802')
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'retreiving a user identifier' do
|
17
|
+
context 'when no identifier exists' do
|
18
|
+
it 'then we should see a Trusona::ResourceNotFound error raised' do
|
19
|
+
expect { Trusona::UserIdentifier.find_by(identifier: 'asdf') }.to(
|
20
|
+
raise_error(Trusona::ResourceNotFoundError)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when a valid identifier exists' do
|
26
|
+
it 'should be successful' do
|
27
|
+
res = Trusona::UserIdentifier.find_by(identifier: @identifier.identifier)
|
28
|
+
expect(res.trusona_id).to eq @identifier.trusona_id
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/trusona.rb
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
require 'trusona/helpers/key_normalizer'
|
6
|
+
require 'trusona/helpers/time_normalizer'
|
7
|
+
|
8
|
+
require 'trusona/version'
|
9
|
+
require 'trusona/errors'
|
10
|
+
require 'trusona/trusonafication'
|
11
|
+
require 'trusona/tru_code'
|
12
|
+
require 'trusona/tru_code_config'
|
13
|
+
require 'trusona/user_account'
|
14
|
+
require 'trusona/user_identifier'
|
15
|
+
require 'trusona/device_user_binding'
|
16
|
+
require 'trusona/identity_document'
|
17
|
+
require 'trusona/device'
|
18
|
+
|
19
|
+
require 'trusona/api/signed_request'
|
20
|
+
require 'trusona/api/verified_response'
|
21
|
+
require 'trusona/api/hashed_message'
|
22
|
+
require 'trusona/api/client'
|
23
|
+
|
24
|
+
require 'trusona/workers/tru_code_creator'
|
25
|
+
require 'trusona/workers/tru_code_finder'
|
26
|
+
require 'trusona/workers/user_account_finder'
|
27
|
+
require 'trusona/workers/user_identifier_finder'
|
28
|
+
require 'trusona/workers/user_identifier_creator'
|
29
|
+
require 'trusona/workers/device_user_binding_creator'
|
30
|
+
require 'trusona/workers/device_user_binding_activator'
|
31
|
+
require 'trusona/workers/trusonafication_creator'
|
32
|
+
require 'trusona/workers/trusonafication_finder'
|
33
|
+
require 'trusona/workers/identity_document_finder'
|
34
|
+
require 'trusona/workers/device_finder'
|
35
|
+
|
36
|
+
require 'trusona/services/base_service'
|
37
|
+
require 'trusona/services/user_accounts_service'
|
38
|
+
require 'trusona/services/account_lookups_service'
|
39
|
+
require 'trusona/services/tru_codes_service'
|
40
|
+
require 'trusona/services/trusonafication_service'
|
41
|
+
require 'trusona/services/tru_codes_service'
|
42
|
+
require 'trusona/services/user_identifiers_service'
|
43
|
+
require 'trusona/services/device_user_bindings_service'
|
44
|
+
require 'trusona/services/identity_documents_service'
|
45
|
+
require 'trusona/services/devices_service'
|
46
|
+
|
47
|
+
require 'trusona/mappers/base_mapper'
|
48
|
+
require 'trusona/mappers/tru_code_mapper'
|
49
|
+
require 'trusona/mappers/nil_mapper'
|
50
|
+
require 'trusona/mappers/trusonafication_mapper'
|
51
|
+
require 'trusona/mappers/tru_code_mapper'
|
52
|
+
require 'trusona/mappers/user_account_mapper'
|
53
|
+
require 'trusona/mappers/user_identifier_mapper'
|
54
|
+
require 'trusona/mappers/device_user_binding_mapper'
|
55
|
+
require 'trusona/mappers/identity_document_mapper'
|
56
|
+
require 'trusona/mappers/device_mapper'
|
57
|
+
|
58
|
+
require 'trusona/resources/validators'
|
59
|
+
require 'trusona/resources/base_resource'
|
60
|
+
require 'trusona/resources/trusonafication'
|
61
|
+
require 'trusona/resources/tru_code'
|
62
|
+
require 'trusona/resources/user_account'
|
63
|
+
require 'trusona/resources/user_identifier'
|
64
|
+
require 'trusona/resources/device_user_binding'
|
65
|
+
require 'trusona/resources/device_user_binding_activation'
|
66
|
+
require 'trusona/resources/identity_document'
|
67
|
+
require 'trusona/resources/device'
|
68
|
+
|
69
|
+
# Trusona
|
70
|
+
module Trusona
|
71
|
+
#
|
72
|
+
## Organizing HTTP and HMAC related items
|
73
|
+
module Api; end
|
74
|
+
#
|
75
|
+
## Organizes Resources
|
76
|
+
module Resources; end
|
77
|
+
|
78
|
+
#
|
79
|
+
## Organizes Services and related behavior
|
80
|
+
module Services; end
|
81
|
+
|
82
|
+
#
|
83
|
+
## Organizes Mappers
|
84
|
+
module Mappers; end
|
85
|
+
|
86
|
+
#
|
87
|
+
## Organizes Workers
|
88
|
+
module Workers; end
|
89
|
+
|
90
|
+
#
|
91
|
+
## Organizes Helpers
|
92
|
+
module Helpers; end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Configures the Trusona SDK with the required parameters by creating and
|
96
|
+
# using an instance of +Trusona::Configuration+.
|
97
|
+
#
|
98
|
+
# Trusona.config do |c|
|
99
|
+
# c.tru_codes_host = ENV['TRUCODES_HOST']
|
100
|
+
# c.api_host = ENV['TRUSONA_API_HOST']
|
101
|
+
# c.secret = ENV['TRUSONA_SECRET']
|
102
|
+
# c.token = ENV['TRUSONA_TOKEN']
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
def self.config
|
106
|
+
yield(@config ||= Configuration.new) if block_given?
|
107
|
+
|
108
|
+
@config ||= Configuration.new
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Represents Trusona configuration
|
113
|
+
#
|
114
|
+
# @attr token [String] The JWT token supplied by Trusona for interacting
|
115
|
+
# with the Trusona API
|
116
|
+
#
|
117
|
+
# @attr secret [String] The secret supplied by Trusona for interacting with
|
118
|
+
# the Trusona API
|
119
|
+
#
|
120
|
+
# @attr_reader api_host [String] The full URL of the Trusona API
|
121
|
+
# (e.g. +https://api.trusona.net+)
|
122
|
+
#
|
123
|
+
# @attr_reader tru_codes_host [String] The full URL of the host responsible
|
124
|
+
# for managing TruCode tru_codes
|
125
|
+
# (e.g. +https://tru_codes.trusona.net+)
|
126
|
+
class Configuration
|
127
|
+
attr_accessor :token, :secret
|
128
|
+
attr_reader :api_host, :tru_codes_host
|
129
|
+
|
130
|
+
##
|
131
|
+
# sets the API host by first ensuring the proper format
|
132
|
+
# @param host [String] The full URL of the Trusona API
|
133
|
+
def api_host=(host)
|
134
|
+
@api_host = parse_host(host)
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# sets the TruCodes host by first ensuring the proper format
|
139
|
+
# @param host [String] The full URL of the TruCodes API
|
140
|
+
def tru_codes_host=(host)
|
141
|
+
@tru_codes_host = parse_host(host)
|
142
|
+
end
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
def parse_host(maybe_host)
|
147
|
+
parsed = URI('')
|
148
|
+
begin
|
149
|
+
parsed = URI(maybe_host).host
|
150
|
+
rescue StandardError
|
151
|
+
parsed = URI('')
|
152
|
+
end
|
153
|
+
|
154
|
+
parsed
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|