trusona 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.travis.yml +9 -8
  5. data/README.md +2 -2
  6. data/lib/trusona.rb +3 -1
  7. data/lib/trusona/api/signed_request.rb +4 -1
  8. data/lib/trusona/api/verified_response.rb +6 -1
  9. data/lib/trusona/identity_document.rb +4 -4
  10. data/lib/trusona/mappers/base_mapper.rb +5 -0
  11. data/lib/trusona/mappers/paired_tru_code_mapper.rb +1 -0
  12. data/lib/trusona/resources/base_resource.rb +1 -1
  13. data/lib/trusona/resources/device_user_binding.rb +1 -0
  14. data/lib/trusona/resources/device_user_binding_activation.rb +2 -1
  15. data/lib/trusona/resources/identity_document.rb +4 -4
  16. data/lib/trusona/resources/paired_tru_code.rb +1 -0
  17. data/lib/trusona/resources/tru_code.rb +2 -1
  18. data/lib/trusona/resources/trusonafication.rb +14 -5
  19. data/lib/trusona/resources/user_account.rb +6 -2
  20. data/lib/trusona/resources/user_identifier.rb +3 -1
  21. data/lib/trusona/resources/validators.rb +1 -0
  22. data/lib/trusona/services/base_service.rb +9 -2
  23. data/lib/trusona/services/device_user_bindings_service.rb +3 -3
  24. data/lib/trusona/services/identity_documents_service.rb +3 -3
  25. data/lib/trusona/services/paired_tru_code_service.rb +1 -0
  26. data/lib/trusona/trusonafication.rb +27 -6
  27. data/lib/trusona/version.rb +1 -1
  28. data/lib/trusona/workers/device_finder.rb +1 -0
  29. data/lib/trusona/workers/identity_document_finder.rb +1 -0
  30. data/lib/trusona/workers/paired_tru_code_finder.rb +1 -0
  31. data/lib/trusona/workers/tru_code_finder.rb +1 -0
  32. data/lib/trusona/workers/trusonafication_canceler.rb +27 -0
  33. data/lib/trusona/workers/trusonafication_creator.rb +2 -1
  34. data/lib/trusona/workers/trusonafication_finder.rb +1 -1
  35. data/lib/trusona/workers/user_identifier_finder.rb +1 -0
  36. data/trusona.gemspec +1 -1
  37. metadata +8 -7
  38. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8493dc6973da717a55a1dd6d7bc9e27cbfbbeb79
4
- data.tar.gz: f5499e8a6a766f4357268506e6a4c414b7c9b04f
2
+ SHA256:
3
+ metadata.gz: 906506ed8d694fd61fe05897fa97ceaa465db24b0b08cdf2decb589d52b3410d
4
+ data.tar.gz: c3bb934222dc999e733b7aec5604bb047693b59be7114b980f72fd83d4f9c3a0
5
5
  SHA512:
6
- metadata.gz: 9762a0980e163dc0bddf95b4a77ca3670eb8a9e4b7b6d9a73223e34c85740e967394bc5754fdf7988381a4d5b3c9ed762128c495502337a6363a1ff5782c4f97
7
- data.tar.gz: 4bbfca2beab08cb3dcdb4cfbea42cce6c9d33fda916b7baf03750baf9434f61cd3f6bb424b56a928a03ffe2978ff96b9bf4b03375c7d067b091a08cb3d9fa53b
6
+ metadata.gz: 4e164cf93f000014441c9bc56efd8ee6768013fedfd395b40356c5914616f724e61c64d12ffe23c232596754c26e279b0165a78acdde56ed8533ddc19f649bc3
7
+ data.tar.gz: ccc02437d947a00c9ec87c14474064bcc0dcee23df105796927f1b42141a9b68853dbd1201a8fe1ddcaf440f4e9165c4a700f38ce911b085c94af5dc22c53a0d
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/.travis.yml CHANGED
@@ -1,21 +1,22 @@
1
- sudo: false
2
1
  language: ruby
3
2
  cache:
4
3
  - bundler
5
4
  rvm:
6
- - 2.4.3
7
- - 2.5.1
5
+ - 2.4
6
+ - 2.5
7
+ - 2.6
8
+ - 2.7
8
9
  before_script:
9
10
  - openssl aes-256-cbc -K $encrypted_2ddff5084a28_key -iv $encrypted_2ddff5084a28_iv -in trusona.key.pem.enc -out trusona.key.pem -d
10
11
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
12
  - chmod +x ./cc-test-reporter
12
13
  - ./cc-test-reporter before-build
13
14
  script:
14
- - bundle exec rspec spec -f p
15
- - bundle exec rubocop lib/**/*.rb -F
16
- - gem build trusona.gemspec
15
+ - bundle exec rspec -f p
16
+ - bundle exec rubocop lib -F
17
+ - echo | bundle exec gem build trusona.gemspec
17
18
  after_script:
18
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
19
+ - if [[ $TRAVIS_PULL_REQUEST == false ]] && [[ $TRAVIS_BRANCH == master ]] && [[ $TRAVIS_TEST_RESULT == 0 ]] && [[ $TRAVIS_JOB_NUMBER =~ ^.*.1$ ]]; then ./cc-test-reporter after-build -t simplecov --exit-code 0; fi
19
20
  deploy:
20
21
  provider: rubygems
21
22
  api_key: $RUBYGEMS_API_KEY
@@ -24,7 +25,7 @@ deploy:
24
25
  skip_cleanup: true
25
26
  on:
26
27
  tags: true
27
- rvm: '2.4.3'
28
+ rvm: '2.6'
28
29
  notifications:
29
30
  slack:
30
31
  on_success: always
data/README.md CHANGED
@@ -4,7 +4,7 @@ Easily interact with the Trusona REST API.
4
4
 
5
5
  ## Current Status
6
6
 
7
- [![Build Status](https://travis-ci.com/lighthauz/trusona-server-sdk-ruby.svg?token=2f2CMAnop6pxz1LFFPky&branch=master)](https://travis-ci.com/lighthauz/trusona-server-sdk-ruby)
7
+ [![Build Status](https://travis-ci.com/trusona/trusona-server-sdk-ruby.svg?branch=master)](https://travis-ci.com/trusona/trusona-server-sdk-ruby)
8
8
  [![Maintainability](https://api.codeclimate.com/v1/badges/ec9f4f928125c278fa39/maintainability)](https://codeclimate.com/github/trusona/trusona-server-sdk-ruby/maintainability)
9
9
  [![Test Coverage](https://api.codeclimate.com/v1/badges/ec9f4f928125c278fa39/test_coverage)](https://codeclimate.com/github/trusona/trusona-server-sdk-ruby/test_coverage)
10
10
 
@@ -171,7 +171,7 @@ Note that the custom fields are not used in the case that the Trusonafication is
171
171
  | Prompt | `prompt` | N | Should the user be prompted to Accept or Reject this Trusonafication? Defaults to `true`. |
172
172
  | Expiration | `expires_at` | N | The ISO-8601 UTC timestamp of the Trusonafication's expiration. Defaults to 90 seconds from creation. |
173
173
  | Custom Fields | `custom_fields` | N | Arbitrary key-value data fields made available to the Trusonafication. Amount of data in the hash is limited to 1MB |
174
- | Callback URL | `callback_url` | N | An HTTPS URL to call when the trusonafication has been completed (accepted, rejected, or expired).<br>The request will be a POST and the body will be the same JSON format as sending a GET request to /api/v2/trusonafications/{id}.<br><br> **NOTE:** The URL should include a randomized segment so it cannot be guessed and abused by third-parties (i.e https://your.domain.com/completed_authentications/f8abe61d-4e51-493f-97b1-464c157624f2). |
174
+ | Callback URL | `callback_url` | N | A HTTPS URL to POST to when the trusonafication has been completed (accepted, rejected, or expired).<br><br> **NOTE:** The URL should include a randomized segment so it cannot be guessed and abused by third-parties e.g. https://your.domain.com/completed_authentications/f8abe61d-4e51-493f-97b1-464c157624f2. |
175
175
 
176
176
  [^1]: You must provide at least one field that would allow Trusona to determine which user to authenticate. The identifier fields are `device_identifier`, `user_identifier`, `email`, and `trucode_id`.
177
177
 
data/lib/trusona.rb CHANGED
@@ -32,6 +32,7 @@ require 'trusona/workers/device_user_binding_creator'
32
32
  require 'trusona/workers/device_user_binding_activator'
33
33
  require 'trusona/workers/trusonafication_creator'
34
34
  require 'trusona/workers/trusonafication_finder'
35
+ require 'trusona/workers/trusonafication_canceler'
35
36
  require 'trusona/workers/identity_document_finder'
36
37
  require 'trusona/workers/device_finder'
37
38
  require 'trusona/workers/user_deactivator'
@@ -118,6 +119,7 @@ module Trusona
118
119
  end
119
120
 
120
121
  raise Trusona::ConfigurationError unless @config
122
+
121
123
  @config
122
124
  end
123
125
 
@@ -136,7 +138,7 @@ module Trusona
136
138
  attr_accessor :token, :secret
137
139
  attr_reader :api_host
138
140
 
139
- def initialize()
141
+ def initialize
140
142
  @api_host = 'api.trusona.net'
141
143
  end
142
144
 
@@ -22,7 +22,7 @@ module Trusona
22
22
  def headers
23
23
  @headers.merge(
24
24
  'x-date' => @date,
25
- 'Date' => @date,
25
+ 'Date' => @date,
26
26
  'X-Date' => @date,
27
27
  'Authorization' => @signature,
28
28
  'Content-Type' => determine_content_type
@@ -33,17 +33,20 @@ module Trusona
33
33
 
34
34
  def determine_content_type
35
35
  return '' if @method == 'GET' || @method == 'DELETE'
36
+
36
37
  Trusona::Api::HTTPClient::CONTENT_TYPE
37
38
  end
38
39
 
39
40
  def build_path(path)
40
41
  return path if @uri.query.nil? || @uri.query.empty?
42
+
41
43
  [@uri.path, @uri.query].join('?')
42
44
  end
43
45
 
44
46
  def build_uri(path, body)
45
47
  return build_uri_with_query(URI(path)) if URI(path).query
46
48
  return build_uri_with_body_as_query(path, body) if valid_hash_body(body)
49
+
47
50
  URI::HTTPS.build(host: @host, path: path)
48
51
  end
49
52
 
@@ -15,7 +15,9 @@ module Trusona
15
15
  end
16
16
 
17
17
  def to_h
18
- JSON.parse(@unverified.body) rescue {}
18
+ JSON.parse(@unverified.body)
19
+ rescue StandardError
20
+ {}
19
21
  end
20
22
 
21
23
  def verified?
@@ -50,6 +52,7 @@ module Trusona
50
52
 
51
53
  def parse_path(uri)
52
54
  return uri.path unless uri.query
55
+
53
56
  [uri.path, uri.query].join('?')
54
57
  end
55
58
 
@@ -61,6 +64,7 @@ module Trusona
61
64
  server = @unverified.headers['server']
62
65
  response_type = @unverified.headers['Content-Type']
63
66
  return response_type unless server == LEGACY_SERVER_HEADER
67
+
64
68
  determine_request_content_type
65
69
  end
66
70
 
@@ -69,6 +73,7 @@ module Trusona
69
73
  return default_type unless @unverified.request
70
74
  return default_type unless @unverified.request.options
71
75
  return default_type unless @unverified.request.options[:headers]
76
+
72
77
  @unverified.request.options[:headers]['Content-Type']
73
78
  end
74
79
 
@@ -28,10 +28,10 @@ module Trusona
28
28
  #
29
29
 
30
30
  def self.all(user_identifier: nil)
31
- # rubocop:disable Metrics/LineLength
31
+ # rubocop:disable Layout/LineLength
32
32
  raise ArgumentError, 'A user identifier is required.' unless user_identifier
33
33
 
34
- # rubocop:enable Metrics/LineLength
34
+ # rubocop:enable Layout/LineLength
35
35
 
36
36
  Trusona::Workers::IdentityDocumentFinder.new.find_all(user_identifier)
37
37
  end
@@ -55,10 +55,10 @@ module Trusona
55
55
  # Trusona::IdentityDocument.find('4FDF044D-89FB-4043-947D-A029CF785B5F')
56
56
  #
57
57
  def self.find(id: nil)
58
- # rubocop:disable Metrics/LineLength
58
+ # rubocop:disable Layout/LineLength
59
59
  raise ArgumentError, 'An Identity Document identifier is required.' unless id
60
60
 
61
- # rubocop:enable Metrics/LineLength
61
+ # rubocop:enable Layout/LineLength
62
62
 
63
63
  Trusona::Workers::IdentityDocumentFinder.new.find(id)
64
64
  end
@@ -27,6 +27,7 @@ module Trusona
27
27
 
28
28
  def map_item(item, existing)
29
29
  return nil if item.nil? || item.empty?
30
+
30
31
  item = normalize_keys(item)
31
32
  item = merge_existing_state(item, existing.to_h)
32
33
  item = map_custom_fields(item)
@@ -40,6 +41,7 @@ module Trusona
40
41
 
41
42
  def map_custom_fields(response)
42
43
  return response if custom_mappings.nil? || custom_mappings.empty?
44
+
43
45
  custom_mappings.each do |original_key, new_key|
44
46
  value = response.delete(original_key)
45
47
  response[new_key] = value
@@ -51,17 +53,20 @@ module Trusona
51
53
  def response_invalid?(response)
52
54
  return true if response.nil?
53
55
  return true unless response.respond_to?(:to_h)
56
+
54
57
  false
55
58
  end
56
59
 
57
60
  def resource_invalid?(resource)
58
61
  return true if resource.nil?
59
62
  return true unless resource.respond_to?(:new)
63
+
60
64
  false
61
65
  end
62
66
 
63
67
  def existing_invalid?(existing)
64
68
  return true unless existing.respond_to?(:to_h)
69
+
65
70
  false
66
71
  end
67
72
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Trusona
4
4
  module Mappers
5
+ ## A Pair Trucode Mapper
5
6
  class PairedTruCodeMapper < BaseMapper
6
7
  def resource
7
8
  Trusona::Resources::PairedTruCode
@@ -17,7 +17,7 @@ module Trusona
17
17
  @params
18
18
  end
19
19
 
20
- def to_json
20
+ def to_json(*_args)
21
21
  JSON(to_h)
22
22
  end
23
23
 
@@ -23,6 +23,7 @@ module Trusona
23
23
  def validate
24
24
  return false unless @user_identifier
25
25
  return false unless @device_identifier
26
+
26
27
  true
27
28
  end
28
29
  end
@@ -11,7 +11,7 @@ module Trusona
11
11
 
12
12
  def initialize(params = {})
13
13
  normalized_params = normalize_keys(params)
14
- @id = normalized_params[:id]
14
+ @id = normalized_params[:id]
15
15
  @active = normalized_params[:active]
16
16
 
17
17
  @params = normalized_params
@@ -20,6 +20,7 @@ module Trusona
20
20
 
21
21
  def validate
22
22
  return false unless @id
23
+
23
24
  true
24
25
  end
25
26
  end
@@ -15,14 +15,14 @@ module Trusona
15
15
  normalized = normalize_keys(params)
16
16
 
17
17
  @params = normalized
18
- @document_hash = normalized[:document_hash]
19
- @id = normalized[:id]
20
- @type = normalized[:type]
18
+ @document_hash = normalized[:document_hash]
19
+ @id = normalized[:id]
20
+ @type = normalized[:type]
21
21
  @verification_status = normalized[:verification_status]
22
22
  @user_identifier = normalized[:user_identifier]
23
23
  end
24
24
 
25
- def to_json
25
+ def to_json(*_args)
26
26
  JSON(
27
27
  hash: @document_hash,
28
28
  id: @id,
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Trusona
4
4
  module Resources
5
+ ## A Paired Trucode
5
6
  class PairedTruCode < BaseResource
6
7
  attr_reader :identifier
7
8
 
@@ -19,7 +19,7 @@ module Trusona
19
19
  raise ArgumentError unless validate
20
20
  end
21
21
 
22
- def to_json
22
+ def to_json(*_args)
23
23
  JSON(to_h)
24
24
  end
25
25
 
@@ -35,6 +35,7 @@ module Trusona
35
35
 
36
36
  def validate
37
37
  return false unless present?(@relying_party_id)
38
+
38
39
  true
39
40
  end
40
41
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Metrics/ClassLength
3
4
  module Trusona
4
5
  module Resources
5
6
  ##
@@ -18,6 +19,7 @@ module Trusona
18
19
  def initialize(params = {})
19
20
  @params = normalize_keys(params)
20
21
  return if @params.nil?
22
+
21
23
  self.accepted_level = determine_accepted_level(@params)
22
24
  self.action = @params[:action]
23
25
  self.device_identifier = @params[:device_identifier]
@@ -44,7 +46,8 @@ module Trusona
44
46
  end
45
47
 
46
48
  # rubocop:disable Metrics/MethodLength
47
- def to_json
49
+ # rubocop:disable Metrics/AbcSize
50
+ def to_json(*_args)
48
51
  JSON(
49
52
  device_identifier: device_identifier,
50
53
  user_identifier: user_identifier,
@@ -64,10 +67,12 @@ module Trusona
64
67
  )
65
68
  end
66
69
  # rubocop:enable Metrics/MethodLength
70
+ # rubocop:enable Metrics/AbcSize
67
71
 
68
72
  def accepted?
69
73
  return true if status == :accepted
70
74
  return true if status == :accepted_at_higher_level
75
+
71
76
  false
72
77
  end
73
78
 
@@ -79,8 +84,8 @@ module Trusona
79
84
  attributes_present && attributes_filled
80
85
  end
81
86
 
82
- # rubocop:disable MethodLength
83
- # rubocop:disable CyclomaticComplexity
87
+ # rubocop:disable Metrics/MethodLength
88
+ # rubocop:disable Metrics/CyclomaticComplexity
84
89
  def status
85
90
  case @status
86
91
  when 'INVALID_TRUSONA_ID'
@@ -103,14 +108,15 @@ module Trusona
103
108
  :invalid
104
109
  end
105
110
  end
106
- # rubocop:enable CyclomaticComplexity
107
- # rubocop:enable MethodLength
111
+ # rubocop:enable Metrics/CyclomaticComplexity
112
+ # rubocop:enable Metrics/MethodLength
108
113
 
109
114
  private
110
115
 
111
116
  def defaulting_to(value, param)
112
117
  return value if param.nil?
113
118
  return value if param.respond_to?(:empty?) && param.empty?
119
+
114
120
  param
115
121
  end
116
122
 
@@ -135,9 +141,12 @@ module Trusona
135
141
  true
136
142
  end
137
143
 
144
+ # rubocop:disable Layout/LineLength
138
145
  def identifier
139
146
  device_identifier || user_identifier || trucode_id || trusona_id || email
140
147
  end
148
+ # rubocop:enable Layout/LineLength
141
149
  end
142
150
  end
143
151
  end
152
+ # rubocop:enable Metrics/ClassLength
@@ -38,12 +38,12 @@ module Trusona
38
38
  @emails = parse_emails(params_with_symbol_keys[:emails])
39
39
  @max_level = parse_max_level(params_with_symbol_keys[:metadata])
40
40
 
41
- @params = params_with_symbol_keys
41
+ @params = params_with_symbol_keys
42
42
  end
43
43
  # rubocop:enable Metrics/MethodLength
44
44
  # rubocop:enable Metrics/AbcSize
45
45
 
46
- def to_json
46
+ def to_json(*_args)
47
47
  JSON(to_h)
48
48
  end
49
49
 
@@ -52,20 +52,24 @@ module Trusona
52
52
  def determine_status(status)
53
53
  return Status::INACTIVE if status == 'inactive'
54
54
  return Status::ACTIVE if status == 'active'
55
+
55
56
  Status::UNKNOWN
56
57
  end
57
58
 
58
59
  def parse_emails(emails)
59
60
  return [] if emails.nil? || emails.empty?
61
+
60
62
  emails.map { |e| UserAccountEmail.new(e) }
61
63
  end
62
64
 
63
65
  def parse_max_level(metadata)
64
66
  return Level::ENTRY unless metadata
67
+
65
68
  level = metadata['max_level'] || metadata[:max_level]
66
69
 
67
70
  return Level::ESSENTIAL if level == 'essential'
68
71
  return Level::EXECUTIVE if level == 'executive'
72
+
69
73
  Level::ENTRY
70
74
  end
71
75
 
@@ -19,7 +19,7 @@ module Trusona
19
19
  @params
20
20
  end
21
21
 
22
- def to_json
22
+ def to_json(*_args)
23
23
  JSON(to_h)
24
24
  end
25
25
 
@@ -36,12 +36,14 @@ module Trusona
36
36
  def attributes_present
37
37
  return false unless @params.key?(:identifier)
38
38
  return false unless @params.key?(:trusona_id)
39
+
39
40
  true
40
41
  end
41
42
 
42
43
  def attributes_filled
43
44
  return false if @params.fetch(:identifier).empty?
44
45
  return false if @params.fetch(:trusona_id).empty?
46
+
45
47
  true
46
48
  end
47
49
  end
@@ -7,6 +7,7 @@ module Trusona
7
7
  module Validators
8
8
  def present?(item)
9
9
  return false if item.nil? || item.to_s.empty?
10
+
10
11
  true
11
12
  end
12
13
 
@@ -21,21 +21,25 @@ module Trusona
21
21
 
22
22
  def get(resource)
23
23
  raise Trusona::InvalidResourceError unless resource.id
24
+
24
25
  handle(@client.get(member_path(resource)), resource)
25
26
  end
26
27
 
27
28
  def create(resource)
28
29
  raise Trusona::InvalidResourceError unless resource.valid?
30
+
29
31
  handle(@client.post(collection_path, resource.to_json), resource)
30
32
  end
31
33
 
32
34
  def update(resource)
33
35
  raise Trusona::InvalidResourceError unless resource.id
36
+
34
37
  handle(@client.patch(member_path(resource), resource.to_json), resource)
35
38
  end
36
39
 
37
40
  def delete(resource)
38
41
  raise Trusona::InvalidResourceError unless resource.id
42
+
39
43
  handle(@client.delete(member_path(resource)), resource)
40
44
  end
41
45
 
@@ -53,12 +57,13 @@ module Trusona
53
57
  raise Trusona::SigningError unless response.verified?
54
58
  end
55
59
 
56
- # rubocop:disable MethodLength
60
+ # rubocop:disable Metrics/MethodLength
57
61
  # rubocop:disable Metrics/CyclomaticComplexity
58
62
  def handle(response, resource = {})
59
63
  @response = response
60
64
 
61
65
  raise if resource.nil?
66
+
62
67
  case response.code
63
68
  when 200..299
64
69
  success(response, resource)
@@ -78,7 +83,7 @@ module Trusona
78
83
  raise Trusona::RequestError, readable_error
79
84
  end
80
85
  end
81
- # rubocop:enable MethodLength
86
+ # rubocop:enable Metrics/MethodLength
82
87
  # rubocop:enable Metrics/CyclomaticComplexity
83
88
 
84
89
  def success(response, resource)
@@ -113,10 +118,12 @@ module Trusona
113
118
  def readable_error
114
119
  default = '[UNKNOWN] Error - An unknown error has occurred.'
115
120
  return default unless @response
121
+
116
122
  body = @response.to_h
117
123
  msg = []
118
124
  msg << "[#{body['error']}] #{body['message']} - #{body['description']}"
119
125
  return msg.join("\n") unless body['field_errors']
126
+
120
127
  body['field_errors'].each do |field|
121
128
  msg << "\t #{field.join(' => ')}"
122
129
  end
@@ -6,9 +6,9 @@ module Trusona
6
6
  ## Device User Bindings Service
7
7
  class DeviceUserBindingsService < BaseService
8
8
  def initialize(
9
- client: Trusona::Api::HTTPClient.new(Trusona.config.api_host),
10
- mapper: Trusona::Mappers::DeviceUserBindingMapper.new
11
- )
9
+ client: Trusona::Api::HTTPClient.new(Trusona.config.api_host),
10
+ mapper: Trusona::Mappers::DeviceUserBindingMapper.new
11
+ )
12
12
  @client = client
13
13
  @mapper = mapper
14
14
  @resource_path = '/api/v2/user_devices'
@@ -6,9 +6,9 @@ module Trusona
6
6
  ## Identity Documents Service
7
7
  class IdentityDocumentsService < BaseService
8
8
  def initialize(
9
- client: Trusona::Api::HTTPClient.new(Trusona.config.api_host),
10
- mapper: Trusona::Mappers::IdentityDocumentMapper.new
11
- )
9
+ client: Trusona::Api::HTTPClient.new(Trusona.config.api_host),
10
+ mapper: Trusona::Mappers::IdentityDocumentMapper.new
11
+ )
12
12
  @client = client
13
13
  @mapper = mapper
14
14
  @resource_path = '/api/v2/identity_documents'
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Trusona
4
4
  module Services
5
+ ## Paired trucode service
5
6
  class PairedTruCodeService < BaseService
6
7
  def initialize(client: Trusona::Api::HTTPClient.new)
7
8
  super(client: client, mapper: Trusona::Mappers::PairedTruCodeMapper.new)
@@ -28,6 +28,29 @@ module Trusona
28
28
  Trusona::Workers::TrusonaficationFinder.new.find(trusonafication_id)
29
29
  end
30
30
 
31
+ ##
32
+ # Cancels existing IN_PROGRESS Trusonafications using their ID. Once
33
+ # canceled the trusonafication can no longer be acted upon.
34
+ #
35
+ # @param trusonafication_id [String] the ID of an existing Trusonafication
36
+ # @raise [Trusona::InvalidRecordIdentifier] if the +trusonafication_id+ is
37
+ # empty or nil.
38
+ # @raise [Trusona::ResourceNotFoundError] if the resource does not exist
39
+ # in the Trusona API
40
+ # @raise [Trusona::UnprocessableEntityError] if the resource could not be
41
+ # cancel because it was not IN_PROGRESS
42
+ #
43
+ # @example
44
+ # Trusona::Trusonafication.cancel('756c1034-2159-4cf9-bd48-662a60a7afff')
45
+ #
46
+ def self.cancel(trusonafication_id)
47
+ if trusonafication_id.nil? || trusonafication_id.strip.empty?
48
+ raise Trusona::InvalidRecordIdentifier, 'Trusonafication ID is missing'
49
+ end
50
+
51
+ Trusona::Workers::TrusonaficationCanceler.new.cancel(trusonafication_id)
52
+ end
53
+
31
54
  ##
32
55
  # Creates a Trusonafication using the supplied options
33
56
  #
@@ -58,14 +81,12 @@ module Trusona
58
81
  # @option params [Hash] :custom_fields Optional data to be associated with
59
82
  # this Trusonafication and can be used to constomize any UX elements. Total
60
83
  # size of data is limited to 1MB.
61
- # @option params [String] :callback_url An HTTPS URL to call when the
62
- # trusonafication has been completed (accepted, rejected, or expired). The
63
- # request will be a POST and the body will be the same JSON format as
64
- # sending a GET request to /api/v2/trusonafications/{id}.
84
+ # @option params [String] :callback_url A HTTPS URL to POST to call when the
85
+ # trusonafication has been completed (accepted, rejected, or expired).
65
86
  #
66
87
  # NOTE: The URL should include a randomized segment so it cannot be guessed
67
- # and abused by third-parties (i.e
68
- # https://your.domain.com/completed_authentications/f8abe61d-4e51-493f-97b1-464c157624f2).
88
+ # and abused by third-parties e.g. https://your.domain.com/completed_authentications/f8abe61d-4e51-493f-97b1-464c157624f2.
89
+ #
69
90
  # @param timeout [Int] (30) The max amount of time, in seconds, to wait
70
91
  # for a response from the Trusona API when polling for a Trusonafication
71
92
  # result
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trusona
4
- VERSION = '2.4.0'
4
+ VERSION = '2.5.0'
5
5
  end
@@ -11,6 +11,7 @@ module Trusona
11
11
 
12
12
  def find(id = nil)
13
13
  raise(ArgumentError, 'A device identifier is required.') unless id
14
+
14
15
  @service.get(Trusona::Resources::Device.new(id: id))
15
16
  end
16
17
  end
@@ -18,6 +18,7 @@ module Trusona
18
18
 
19
19
  def find(id = nil)
20
20
  raise(ArgumentError, 'An Identity Document id is required.') unless id
21
+
21
22
  @service.get(Trusona::Resources::IdentityDocument.new(id: id))
22
23
  end
23
24
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Trusona
4
4
  module Workers
5
+ # A Paired Trucode Finder
5
6
  class PairedTruCodeFinder
6
7
  def initialize(service: Trusona::Services::PairedTruCodeService.new)
7
8
  @service = service
@@ -11,6 +11,7 @@ module Trusona
11
11
 
12
12
  def find(id)
13
13
  raise ArgumentError, 'Missing TruCode Id' unless id
14
+
14
15
  resource = Trusona::Resources::BaseResource.new(id: id)
15
16
  @service.get(resource)
16
17
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Trusona
4
+ module Workers
5
+ #
6
+ ## Cancel a Trusonafication
7
+ class TrusonaficationCanceler
8
+ def initialize(service: nil)
9
+ @service = service || Trusona::Services::TrusonaficationService.new
10
+ end
11
+
12
+ def cancel(trusonafication_id)
13
+ if trusonafication_id.nil? || trusonafication_id.strip.empty?
14
+ raise(
15
+ Trusona::InvalidResourceError,
16
+ 'Trusonafication Id cannot be empty or nil'
17
+ )
18
+ end
19
+
20
+ resource = Trusona::Resources::Trusonafication.new(
21
+ id: trusonafication_id
22
+ )
23
+ @service.delete(resource)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -14,6 +14,7 @@ module Trusona
14
14
  def create(params: {}, timeout: nil, &block)
15
15
  raise ArgumentError, 'Missing or empty params hash' if
16
16
  params.nil? || params.empty?
17
+
17
18
  resource = Trusona::Resources::Trusonafication.new(params)
18
19
  trusonafication = @service.create(resource)
19
20
  return trusonafication unless block_given?
@@ -43,4 +44,4 @@ module Trusona
43
44
  # rubocop:enable Metrics/MethodLength
44
45
  end
45
46
  end
46
- end
47
+ end
@@ -24,4 +24,4 @@ module Trusona
24
24
  end
25
25
  end
26
26
  end
27
- end
27
+ end
@@ -12,6 +12,7 @@ module Trusona
12
12
  def find(opts)
13
13
  raise ArgumentError, 'Missing user identifier' unless
14
14
  contains_required_arguments(opts)
15
+
15
16
  @service.get(build_resource(opts))
16
17
  end
17
18
 
data/trusona.gemspec CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency 'rspec', '~> 3.0'
40
40
  spec.add_development_dependency 'rspec-wait', '~> 0.0'
41
41
  spec.add_development_dependency 'rubocop', '~> 0.49'
42
- spec.add_development_dependency 'simplecov', '~> 0.14'
42
+ spec.add_development_dependency 'simplecov', '0.17'
43
43
  spec.add_development_dependency 'yard', '~> 0.9'
44
44
  spec.add_development_dependency 'webmock', '~> 3.5'
45
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trusona
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trusona
@@ -43,7 +43,7 @@ cert_chain:
43
43
  ++bYzfdt4k2vDjnMpWjx4gb0LFsLOGKsPlw9TBgCDqu96KTAbSnHh/9GIkGn76Kw
44
44
  eNCk84I=
45
45
  -----END CERTIFICATE-----
46
- date: 2019-07-31 00:00:00.000000000 Z
46
+ date: 2020-02-04 00:00:00.000000000 Z
47
47
  dependencies:
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: httparty
@@ -217,16 +217,16 @@ dependencies:
217
217
  name: simplecov
218
218
  requirement: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - "~>"
220
+ - - '='
221
221
  - !ruby/object:Gem::Version
222
- version: '0.14'
222
+ version: '0.17'
223
223
  type: :development
224
224
  prerelease: false
225
225
  version_requirements: !ruby/object:Gem::Requirement
226
226
  requirements:
227
- - - "~>"
227
+ - - '='
228
228
  - !ruby/object:Gem::Version
229
- version: '0.14'
229
+ version: '0.17'
230
230
  - !ruby/object:Gem::Dependency
231
231
  name: yard
232
232
  requirement: !ruby/object:Gem::Requirement
@@ -346,6 +346,7 @@ files:
346
346
  - lib/trusona/workers/paired_tru_code_finder.rb
347
347
  - lib/trusona/workers/tru_code_creator.rb
348
348
  - lib/trusona/workers/tru_code_finder.rb
349
+ - lib/trusona/workers/trusonafication_canceler.rb
349
350
  - lib/trusona/workers/trusonafication_creator.rb
350
351
  - lib/trusona/workers/trusonafication_finder.rb
351
352
  - lib/trusona/workers/user_account_finder.rb
@@ -375,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
375
376
  version: '0'
376
377
  requirements: []
377
378
  rubyforge_project:
378
- rubygems_version: 2.6.14
379
+ rubygems_version: 2.7.7
379
380
  signing_key:
380
381
  specification_version: 4
381
382
  summary: Trusona REST API wrapper
metadata.gz.sig CHANGED
Binary file