workos 2.2.1 → 2.5.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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +4 -1
  4. data/lib/workos/audit_trail.rb +1 -1
  5. data/lib/workos/challenge.rb +1 -1
  6. data/lib/workos/client.rb +14 -5
  7. data/lib/workos/configuration.rb +17 -0
  8. data/lib/workos/directory_group.rb +22 -1
  9. data/lib/workos/directory_sync.rb +3 -1
  10. data/lib/workos/directory_user.rb +12 -1
  11. data/lib/workos/errors.rb +3 -0
  12. data/lib/workos/factor.rb +1 -6
  13. data/lib/workos/mfa.rb +22 -7
  14. data/lib/workos/organizations.rb +1 -1
  15. data/lib/workos/passwordless.rb +0 -1
  16. data/lib/workos/portal.rb +0 -1
  17. data/lib/workos/sso.rb +2 -2
  18. data/lib/workos/types/challenge_struct.rb +1 -1
  19. data/lib/workos/types/directory_group_struct.rb +6 -0
  20. data/lib/workos/types/directory_user_struct.rb +2 -0
  21. data/lib/workos/types/factor_struct.rb +0 -1
  22. data/lib/workos/types/{verify_factor_struct.rb → verify_challenge_struct.rb} +3 -3
  23. data/lib/workos/types.rb +1 -1
  24. data/lib/workos/{verify_factor.rb → verify_challenge.rb} +5 -6
  25. data/lib/workos/version.rb +1 -1
  26. data/lib/workos.rb +17 -7
  27. data/spec/lib/workos/configuration_spec.rb +61 -0
  28. data/spec/lib/workos/directory_sync_spec.rb +26 -19
  29. data/spec/lib/workos/directory_user_spec.rb +36 -0
  30. data/spec/lib/workos/mfa_spec.rb +93 -74
  31. data/spec/lib/workos/sso_spec.rb +1 -1
  32. data/spec/spec_helper.rb +2 -2
  33. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group.yml +47 -29
  34. data/spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml +28 -31
  35. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +46 -32
  36. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +47 -31
  37. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +46 -34
  38. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +41 -31
  39. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_no_options.yml +36 -26
  40. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +38 -28
  41. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_generic_valid.yml +2 -2
  42. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_sms_valid.yml +2 -2
  43. data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_totp_valid.yml +3 -3
  44. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_generic_valid.yml +1 -1
  45. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_sms_valid.yml +1 -1
  46. data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_totp_valid.yml +1 -1
  47. data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_valid.yml +1 -1
  48. data/spec/support/fixtures/vcr_cassettes/mfa/{verify_factor_generic_expired.yml → verify_challenge_generic_expired.yml} +2 -2
  49. data/spec/support/fixtures/vcr_cassettes/mfa/{verify_factor_generic_invalid.yml → verify_challenge_generic_invalid.yml} +2 -2
  50. data/spec/support/fixtures/vcr_cassettes/mfa/{verify_factor_generic_valid.yml → verify_challenge_generic_valid.yml} +2 -2
  51. data/spec/support/fixtures/vcr_cassettes/mfa/{verify_factor_generic_valid_is_false.yml → verify_challenge_generic_valid_is_false.yml} +2 -2
  52. metadata +18 -16
  53. data/lib/workos/base.rb +0 -18
  54. data/spec/lib/workos/base_spec.rb +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 286a2f14af16bfc7b9c77e7938c2b8d7366f4a03f9fca4c7892f85f60562e433
4
- data.tar.gz: 8970807084e7022beb9bb1523c270e645c340e42e452d7f0d7ea0d64958cf1ea
3
+ metadata.gz: 014f85386dcfba661f0a74ae427127257b953a2791b4667c72d9b1961237a93b
4
+ data.tar.gz: 7290ad0b22df3751f1183f5465d35f56828c4fd1b0e519c29c208138b67db3fe
5
5
  SHA512:
6
- metadata.gz: e4d3af795ee51a5cb807fda2bdffc2217e0150ec2f4ffe51fb86daab6e376ecd240f03f1b204db2a72265ebc61d5a9c227a13924a262bb6cf7011ce9c87df177
7
- data.tar.gz: a8977f9bff244978c9c1935e46a411e4e564a86ed51d7523780feab31212857771813190c523f64d5640f13b393ba5f5a3df3ced5729a7ad34df0cdfa3b6014e
6
+ metadata.gz: 766ef6dfba39dc072dab56a7fbfbcaa4484e39bbd444dc3c9148894e791b232689e7210a13f178442e595a67ac3c74aed64ee377ddad342f6105b2103513bbec
7
+ data.tar.gz: 759b73ee9afe91742acb8ee818d03bc397a6760d44f88dbfa3989439e4e396cacc2b71dd866ab90495bb7c1e2b430709987f09335a20b4a08b123aedfa1003d8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- workos (2.2.1)
4
+ workos (2.5.0)
5
5
  sorbet-runtime (~> 0.5)
6
6
 
7
7
  GEM
@@ -60,7 +60,7 @@ GEM
60
60
  simplecov_json_formatter (0.1.2)
61
61
  sorbet (0.5.6388)
62
62
  sorbet-static (= 0.5.6388)
63
- sorbet-runtime (0.5.9944)
63
+ sorbet-runtime (0.5.10207)
64
64
  sorbet-static (0.5.6388-universal-darwin-14)
65
65
  sorbet-static (0.5.6388-universal-darwin-15)
66
66
  sorbet-static (0.5.6388-universal-darwin-16)
data/README.md CHANGED
@@ -35,7 +35,10 @@ Or, you may set the key yourself, such as in an initializer in your application
35
35
  ```ruby
36
36
  # /config/initializers/workos.rb
37
37
 
38
- WorkOS.key = '[your api key]'
38
+ WorkOS.configure do |config|
39
+ config.key = '[your api key]'
40
+ config.timeout = 120
41
+ end
39
42
  ```
40
43
 
41
44
  ## SDK Versioning
@@ -12,7 +12,6 @@ module WorkOS
12
12
  module AuditTrail
13
13
  class << self
14
14
  extend T::Sig
15
- include Base
16
15
  include Client
17
16
 
18
17
  # Create an Audit Trail event.
@@ -65,6 +64,7 @@ module WorkOS
65
64
  # @option options [String] before Event ID to look before
66
65
  # @option options [String] after Event ID to look after
67
66
  # @option options [Integer] limit Number of Events to return
67
+ # @option options [String] order The order in which to paginate records
68
68
  # @option options [Array<String>] group List of Groups to filter for
69
69
  # @option options [Array<String>] action List of Actions to filter for
70
70
  # @option options [Array<String>] action_type List of Action Types to
@@ -16,7 +16,7 @@ module WorkOS
16
16
  raw = parse_json(json)
17
17
  @id = T.let(raw.id, String)
18
18
  @object = T.let(raw.object, String)
19
- @expires_at = raw.expires_at
19
+ @expires_at = T.let(raw.expires_at, String)
20
20
  @code = raw.code
21
21
  @authentication_factor_id = T.let(raw.authentication_factor_id, String)
22
22
  @created_at = T.let(raw.created_at, String)
data/lib/workos/client.rb CHANGED
@@ -11,6 +11,9 @@ module WorkOS
11
11
  def client
12
12
  Net::HTTP.new(WorkOS::API_HOSTNAME, 443).tap do |http_client|
13
13
  http_client.use_ssl = true
14
+ http_client.open_timeout = WorkOS.config.timeout
15
+ http_client.read_timeout = WorkOS.config.timeout
16
+ http_client.write_timeout = WorkOS.config.timeout
14
17
  end
15
18
  end
16
19
 
@@ -20,7 +23,13 @@ module WorkOS
20
23
  ).returns(::T.untyped)
21
24
  end
22
25
  def execute_request(request:)
23
- response = client.request(request)
26
+ begin
27
+ response = client.request(request)
28
+ rescue Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout
29
+ raise TimeoutError.new(
30
+ message: 'API Timeout Error',
31
+ )
32
+ end
24
33
 
25
34
  http_status = response.code.to_i
26
35
  handle_error_response(response: response) if http_status >= 400
@@ -45,7 +54,7 @@ module WorkOS
45
54
  'Content-Type' => 'application/json',
46
55
  )
47
56
 
48
- request['Authorization'] = "Bearer #{access_token || WorkOS.key!}" if auth
57
+ request['Authorization'] = "Bearer #{access_token || WorkOS.config.key!}" if auth
49
58
  request['User-Agent'] = user_agent
50
59
  request
51
60
  end
@@ -61,7 +70,7 @@ module WorkOS
61
70
  def post_request(path:, auth: false, idempotency_key: nil, body: nil)
62
71
  request = Net::HTTP::Post.new(path, 'Content-Type' => 'application/json')
63
72
  request.body = body.to_json if body
64
- request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
73
+ request['Authorization'] = "Bearer #{WorkOS.config.key!}" if auth
65
74
  request['Idempotency-Key'] = idempotency_key if idempotency_key
66
75
  request['User-Agent'] = user_agent
67
76
  request
@@ -83,7 +92,7 @@ module WorkOS
83
92
  'Content-Type' => 'application/json',
84
93
  )
85
94
 
86
- request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
95
+ request['Authorization'] = "Bearer #{WorkOS.config.key!}" if auth
87
96
  request['User-Agent'] = user_agent
88
97
  request
89
98
  end
@@ -99,7 +108,7 @@ module WorkOS
99
108
  def put_request(path:, auth: false, idempotency_key: nil, body: nil)
100
109
  request = Net::HTTP::Put.new(path, 'Content-Type' => 'application/json')
101
110
  request.body = body.to_json if body
102
- request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
111
+ request['Authorization'] = "Bearer #{WorkOS.config.key!}" if auth
103
112
  request['Idempotency-Key'] = idempotency_key if idempotency_key
104
113
  request['User-Agent'] = user_agent
105
114
  request
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ module WorkOS
5
+ # Configuration class sets config initializer
6
+ class Configuration
7
+ attr_accessor :timeout, :key
8
+
9
+ def initialize
10
+ @timeout = 60
11
+ end
12
+
13
+ def key!
14
+ key or raise '`WorkOS.config.key` not set'
15
+ end
16
+ end
17
+ end
@@ -9,22 +9,37 @@ module WorkOS
9
9
  include HashProvider
10
10
  extend T::Sig
11
11
 
12
- attr_accessor :id, :name, :custom_attributes, :raw_attributes
12
+ attr_accessor :id, :directory_id, :idp_id, :name, :created_at, :updated_at,
13
+ :raw_attributes, :organization_id
13
14
 
15
+ # rubocop:disable Metrics/AbcSize
14
16
  sig { params(json: String).void }
15
17
  def initialize(json)
16
18
  raw = parse_json(json)
17
19
 
18
20
  @id = T.let(raw.id, String)
21
+ @directory_id = T.let(raw.directory_id, String)
22
+ @organization_id = raw.organization_id
23
+ @idp_id = T.let(raw.idp_id, String)
19
24
  @name = T.let(raw.name, String)
25
+ @created_at = T.let(raw.created_at, String)
26
+ @updated_at = T.let(raw.updated_at, String)
27
+ @raw_attributes = raw.raw_attributes
20
28
 
21
29
  replace_without_warning(to_json)
22
30
  end
31
+ # rubocop:enable Metrics/AbcSize
23
32
 
24
33
  def to_json(*)
25
34
  {
26
35
  id: id,
36
+ directory_id: directory_id,
37
+ organization_id: organization_id,
38
+ idp_id: idp_id,
27
39
  name: name,
40
+ created_at: created_at,
41
+ updated_at: updated_at,
42
+ raw_attributes: raw_attributes,
28
43
  }
29
44
  end
30
45
 
@@ -40,7 +55,13 @@ module WorkOS
40
55
 
41
56
  WorkOS::Types::DirectoryGroupStruct.new(
42
57
  id: hash[:id],
58
+ directory_id: hash[:directory_id],
59
+ organization_id: hash[:organization_id],
60
+ idp_id: hash[:idp_id],
43
61
  name: hash[:name],
62
+ created_at: hash[:created_at],
63
+ updated_at: hash[:updated_at],
64
+ raw_attributes: hash[:raw_attributes],
44
65
  )
45
66
  end
46
67
  end
@@ -12,7 +12,6 @@ module WorkOS
12
12
  module DirectorySync
13
13
  class << self
14
14
  extend T::Sig
15
- include Base
16
15
  include Client
17
16
 
18
17
  # Retrieve directories.
@@ -22,6 +21,7 @@ module WorkOS
22
21
  # retrieved.
23
22
  # @option options [String] search A search term for direcory names.
24
23
  # @option options [String] limit Maximum number of records to return.
24
+ # @option options [String] order The order in which to paginate records
25
25
  # @option options [String] before Pagination cursor to receive records
26
26
  # before a provided Directory ID.
27
27
  # @option options [String] after Pagination cursor to receive records
@@ -91,6 +91,7 @@ module WorkOS
91
91
  # @option options [String] user The ID of the directory user whose
92
92
  # directory groups will be retrieved.
93
93
  # @option options [String] limit Maximum number of records to return.
94
+ # @option options [String] order The order in which to paginate records
94
95
  # @option options [String] before Pagination cursor to receive records
95
96
  # before a provided Directory Group ID.
96
97
  # @option options [String] after Pagination cursor to receive records
@@ -130,6 +131,7 @@ module WorkOS
130
131
  # @option options [String] user The ID of the directory group whose
131
132
  # directory users will be retrieved.
132
133
  # @option options [String] limit Maximum number of records to return.
134
+ # @option options [String] order The order in which to paginate records
133
135
  # @option options [String] before Pagination cursor to receive records
134
136
  # before a provided Directory User ID.
135
137
  # @option options [String] after Pagination cursor to receive records
@@ -10,7 +10,7 @@ module WorkOS
10
10
  extend T::Sig
11
11
 
12
12
  attr_accessor :id, :idp_id, :emails, :first_name, :last_name, :username, :state,
13
- :groups, :custom_attributes, :raw_attributes
13
+ :groups, :custom_attributes, :raw_attributes, :directory_id, :organization_id
14
14
 
15
15
  # rubocop:disable Metrics/AbcSize
16
16
  sig { params(json: String).void }
@@ -18,6 +18,8 @@ module WorkOS
18
18
  raw = parse_json(json)
19
19
 
20
20
  @id = T.let(raw.id, String)
21
+ @directory_id = T.let(raw.directory_id, String)
22
+ @organization_id = raw.organization_id
21
23
  @idp_id = T.let(raw.idp_id, String)
22
24
  @emails = T.let(raw.emails, Array)
23
25
  @first_name = raw.first_name
@@ -35,6 +37,8 @@ module WorkOS
35
37
  def to_json(*)
36
38
  {
37
39
  id: id,
40
+ directory_id: directory_id,
41
+ organization_id: organization_id,
38
42
  idp_id: idp_id,
39
43
  emails: emails,
40
44
  first_name: first_name,
@@ -47,6 +51,11 @@ module WorkOS
47
51
  }
48
52
  end
49
53
 
54
+ def primary_email
55
+ primary_email = (emails || []).find { |email| email[:primary] }
56
+ return primary_email[:value] if primary_email
57
+ end
58
+
50
59
  private
51
60
 
52
61
  sig do
@@ -59,6 +68,8 @@ module WorkOS
59
68
 
60
69
  WorkOS::Types::DirectoryUserStruct.new(
61
70
  id: hash[:id],
71
+ directory_id: hash[:directory_id],
72
+ organization_id: hash[:organization_id],
62
73
  idp_id: hash[:idp_id],
63
74
  emails: hash[:emails],
64
75
  first_name: hash[:first_name],
data/lib/workos/errors.rb CHANGED
@@ -61,4 +61,7 @@ module WorkOS
61
61
  # SignatureVerificationError is raised when the signature verification for a
62
62
  # webhook fails
63
63
  class SignatureVerificationError < WorkOSError; end
64
+
65
+ # TimeoutError is raised when the HTTP request to the API times out
66
+ class TimeoutError < WorkOSError; end
64
67
  end
data/lib/workos/factor.rb CHANGED
@@ -7,15 +7,13 @@ module WorkOS
7
7
  # in DirectoryUser space, and is instantiated internally but exposed.
8
8
  class Factor
9
9
  include HashProvider
10
- # rubocop:disable Metrics/AbcSize
11
10
  extend T::Sig
12
- attr_accessor :id, :environment_id, :object, :type, :sms, :totp, :updated_at, :created_at
11
+ attr_accessor :id, :object, :type, :sms, :totp, :updated_at, :created_at
13
12
 
14
13
  sig { params(json: String).void }
15
14
  def initialize(json)
16
15
  raw = parse_json(json)
17
16
  @id = T.let(raw.id, String)
18
- @environment_id = T.let(raw.environment_id, String)
19
17
  @object = T.let(raw.object, String)
20
18
  @type = T.let(raw.type, String)
21
19
  @created_at = T.let(raw.created_at, String)
@@ -27,7 +25,6 @@ module WorkOS
27
25
  def to_json(*)
28
26
  {
29
27
  id: id,
30
- environment_id: environment_id,
31
28
  object: object,
32
29
  type: type,
33
30
  totp: totp,
@@ -45,7 +42,6 @@ module WorkOS
45
42
 
46
43
  WorkOS::Types::FactorStruct.new(
47
44
  id: hash[:id],
48
- environment_id: hash[:environment_id],
49
45
  object: hash[:object],
50
46
  type: hash[:type],
51
47
  totp: hash[:totp],
@@ -54,6 +50,5 @@ module WorkOS
54
50
  updated_at: hash[:updated_at],
55
51
  )
56
52
  end
57
- # rubocop:enable Metrics/AbcSize
58
53
  end
59
54
  end
data/lib/workos/mfa.rb CHANGED
@@ -11,7 +11,6 @@ module WorkOS
11
11
  module MFA
12
12
  class << self
13
13
  extend T::Sig
14
- include Base
15
14
  include Client
16
15
  sig { params(id: String).returns(T::Boolean) }
17
16
  def delete_factor(id:)
@@ -122,9 +121,8 @@ module WorkOS
122
121
  auth: true,
123
122
  body: {
124
123
  sms_template: sms_template,
125
- authentication_factor_id: authentication_factor_id,
126
124
  },
127
- path: '/auth/factors/challenge',
125
+ path: "/auth/factors/#{authentication_factor_id}/challenge",
128
126
  )
129
127
 
130
128
  response = execute_request(request: request)
@@ -135,30 +133,47 @@ module WorkOS
135
133
  params(
136
134
  authentication_challenge_id: T.nilable(String),
137
135
  code: T.nilable(String),
138
- ).returns(WorkOS::VerifyFactor)
136
+ ).returns(WorkOS::VerifyChallenge)
139
137
  end
140
138
  def verify_factor(
141
139
  authentication_challenge_id: nil,
142
140
  code: nil
143
141
  )
142
+ warn '[DEPRECATION] `verify_factor` is deprecated. Please use `verify_challenge` instead.'
143
+
144
+ verify_challenge(
145
+ authentication_challenge_id: authentication_challenge_id,
146
+ code: code,
147
+ )
148
+ end
149
+
150
+ sig do
151
+ params(
152
+ authentication_challenge_id: T.nilable(String),
153
+ code: T.nilable(String),
154
+ ).returns(WorkOS::VerifyChallenge)
155
+ end
156
+ def verify_challenge(
157
+ authentication_challenge_id: nil,
158
+ code: nil
159
+ )
144
160
 
145
161
  if authentication_challenge_id.nil? || code.nil?
146
162
  raise ArgumentError, "Incomplete arguments: 'authentication_challenge_id' and 'code' are required arguments"
147
163
  end
148
164
 
149
165
  options = {
150
- "authentication_challenge_id": authentication_challenge_id,
151
166
  "code": code,
152
167
  }
153
168
 
154
169
  response = execute_request(
155
170
  request: post_request(
156
- path: '/auth/factors/verify',
171
+ path: "/auth/challenges/#{authentication_challenge_id}/verify",
157
172
  auth: true,
158
173
  body: options,
159
174
  ),
160
175
  )
161
- WorkOS::VerifyFactor.new(response.body)
176
+ WorkOS::VerifyChallenge.new(response.body)
162
177
  end
163
178
  end
164
179
  end
@@ -8,7 +8,6 @@ module WorkOS
8
8
  module Organizations
9
9
  class << self
10
10
  extend T::Sig
11
- include Base
12
11
  include Client
13
12
 
14
13
  # Retrieve a list of organizations that have connections configured
@@ -21,6 +20,7 @@ module WorkOS
21
20
  # @param [String] after A pagination argument used to request
22
21
  # organizations after the provided Organization ID.
23
22
  # @param [Integer] limit A pagination argument used to limit the number
23
+ # @param [String] order The order in which to paginate records
24
24
  # of listed Organizations that are returned.
25
25
  sig do
26
26
  params(
@@ -12,7 +12,6 @@ module WorkOS
12
12
  module Passwordless
13
13
  class << self
14
14
  extend T::Sig
15
- include Base
16
15
  include Client
17
16
 
18
17
  # Create a Passwordless Session.
data/lib/workos/portal.rb CHANGED
@@ -9,7 +9,6 @@ module WorkOS
9
9
  module Portal
10
10
  class << self
11
11
  extend T::Sig
12
- include Base
13
12
  include Client
14
13
 
15
14
  GENERATE_LINK_INTENTS = WorkOS::Types::Intent.values.map(&:serialize).
data/lib/workos/sso.rb CHANGED
@@ -13,7 +13,6 @@ module WorkOS
13
13
  module SSO
14
14
  class << self
15
15
  extend T::Sig
16
- include Base
17
16
  include Client
18
17
 
19
18
  PROVIDERS = WorkOS::Types::Provider.values.map(&:serialize).freeze
@@ -142,7 +141,7 @@ module WorkOS
142
141
  def profile_and_token(code:, client_id: nil)
143
142
  body = {
144
143
  client_id: client_id,
145
- client_secret: WorkOS.key!,
144
+ client_secret: WorkOS.config.key!,
146
145
  grant_type: 'authorization_code',
147
146
  code: code,
148
147
  }
@@ -163,6 +162,7 @@ module WorkOS
163
162
  # @option options [String] organization_id The id of the organization
164
163
  # of the connections to be retrieved.
165
164
  # @option options [String] limit Maximum number of records to return.
165
+ # @option options [String] order The order in which to paginate records
166
166
  # @option options [String] before Pagination cursor to receive records
167
167
  # before a provided Connection ID.
168
168
  # @option options [String] after Pagination cursor to receive records
@@ -8,7 +8,7 @@ module WorkOS
8
8
  class ChallengeStruct < T::Struct
9
9
  const :id, String
10
10
  const :object, String
11
- const :expires_at, T.nilable(String)
11
+ const :expires_at, String
12
12
  const :code, T.nilable(String)
13
13
  const :authentication_factor_id, String
14
14
  const :created_at, String
@@ -7,7 +7,13 @@ module WorkOS
7
7
  # for the DirectoryGroup class
8
8
  class DirectoryGroupStruct < T::Struct
9
9
  const :id, String
10
+ const :directory_id, String
11
+ const :organization_id, T.nilable(String)
12
+ const :idp_id, String
10
13
  const :name, String
14
+ const :created_at, String
15
+ const :updated_at, String
16
+ const :raw_attributes, T::Hash[Symbol, Object]
11
17
  end
12
18
  end
13
19
  end
@@ -7,6 +7,8 @@ module WorkOS
7
7
  # for the DirectoryUser class
8
8
  class DirectoryUserStruct < T::Struct
9
9
  const :id, String
10
+ const :directory_id, String
11
+ const :organization_id, T.nilable(String)
10
12
  const :idp_id, String
11
13
  const :emails, T::Array[T.untyped]
12
14
  const :first_name, T.nilable(String)
@@ -7,7 +7,6 @@ module WorkOS
7
7
  # for the Factor class
8
8
  class FactorStruct < T::Struct
9
9
  const :id, String
10
- const :environment_id, String
11
10
  const :object, String
12
11
  const :type, String
13
12
  const :totp, T.nilable(T::Hash[Symbol, Object])
@@ -3,9 +3,9 @@
3
3
 
4
4
  module WorkOS
5
5
  module Types
6
- # This VerifyFactorStruct acts as a typed interface
7
- # for the Factor class
8
- class VerifyFactorStruct < T::Struct
6
+ # This VerifyChallengeStruct acts as a typed interface
7
+ # for the VerifyChallenge class
8
+ class VerifyChallengeStruct < T::Struct
9
9
  const :challenge, T.nilable(T::Hash[Symbol, Object])
10
10
  const :valid, T::Boolean
11
11
  end
data/lib/workos/types.rb CHANGED
@@ -18,6 +18,6 @@ module WorkOS
18
18
  require_relative 'types/webhook_struct'
19
19
  require_relative 'types/factor_struct'
20
20
  require_relative 'types/challenge_struct'
21
- require_relative 'types/verify_factor_struct'
21
+ require_relative 'types/verify_challenge_struct'
22
22
  end
23
23
  end
@@ -2,10 +2,9 @@
2
2
  # typed: false
3
3
 
4
4
  module WorkOS
5
- # The VerifyFactor class provides a lightweight wrapper around
6
- # a WorkOS DirectoryUser resource. This class is not meant to be instantiated
7
- # in DirectoryUser space, and is instantiated internally but exposed.
8
- class VerifyFactor
5
+ # The VerifyChallenge class provides a lightweight wrapper around
6
+ # a WorkOS Authentication Challenge resource.
7
+ class VerifyChallenge
9
8
  include HashProvider
10
9
  extend T::Sig
11
10
 
@@ -27,11 +26,11 @@ module WorkOS
27
26
 
28
27
  private
29
28
 
30
- sig { params(json_string: String).returns(WorkOS::Types::VerifyFactorStruct) }
29
+ sig { params(json_string: String).returns(WorkOS::Types::VerifyChallengeStruct) }
31
30
  def parse_json(json_string)
32
31
  hash = JSON.parse(json_string, symbolize_names: true)
33
32
 
34
- WorkOS::Types::VerifyFactorStruct.new(
33
+ WorkOS::Types::VerifyChallengeStruct.new(
35
34
  challenge: hash[:challenge],
36
35
  valid: hash[:valid],
37
36
  )
@@ -2,5 +2,5 @@
2
2
  # typed: strong
3
3
 
4
4
  module WorkOS
5
- VERSION = '2.2.1'
5
+ VERSION = '2.5.0'
6
6
  end
data/lib/workos.rb CHANGED
@@ -5,6 +5,7 @@ require 'workos/version'
5
5
  require 'sorbet-runtime'
6
6
  require 'json'
7
7
  require 'workos/hash_provider'
8
+ require 'workos/configuration'
8
9
 
9
10
  # Use the WorkOS module to authenticate your
10
11
  # requests to the WorkOS API. The gem will read
@@ -16,20 +17,28 @@ module WorkOS
16
17
  API_HOSTNAME = ENV['WORKOS_API_HOSTNAME'] || 'api.workos.com'
17
18
 
18
19
  def self.key=(value)
19
- Base.key = value
20
+ warn '`WorkOS.key=` is deprecated. Use `WorkOS.configure` instead.'
21
+
22
+ config.key = value
20
23
  end
21
24
 
22
25
  def self.key
23
- Base.key
26
+ warn '`WorkOS.key` is deprecated. Use `WorkOS.configure` instead.'
27
+
28
+ config.key
29
+ end
30
+
31
+ def self.config
32
+ @config ||= Configuration.new
24
33
  end
25
34
 
26
- def self.key!
27
- key || raise('WorkOS.key not set')
35
+ def self.configure
36
+ yield(config)
28
37
  end
29
38
 
30
39
  autoload :Types, 'workos/types'
31
- autoload :Base, 'workos/base'
32
40
  autoload :Client, 'workos/client'
41
+ autoload :Configuration, 'workos/configuration'
33
42
  autoload :AuditTrail, 'workos/audit_trail'
34
43
  autoload :Connection, 'workos/connection'
35
44
  autoload :DirectorySync, 'workos/directory_sync'
@@ -48,7 +57,7 @@ module WorkOS
48
57
  autoload :MFA, 'workos/mfa'
49
58
  autoload :Factor, 'workos/factor'
50
59
  autoload :Challenge, 'workos/challenge'
51
- autoload :VerifyFactor, 'workos/verify_factor'
60
+ autoload :VerifyChallenge, 'workos/verify_challenge'
52
61
  autoload :DeprecatedHashWrapper, 'workos/deprecated_hash_wrapper'
53
62
 
54
63
 
@@ -57,9 +66,10 @@ module WorkOS
57
66
  autoload :AuthenticationError, 'workos/errors'
58
67
  autoload :InvalidRequestError, 'workos/errors'
59
68
  autoload :SignatureVerificationError, 'workos/errors'
69
+ autoload :TimeoutError, 'workos/errors'
60
70
 
61
71
  # Remove WORKOS_KEY at some point in the future. Keeping it here now for
62
72
  # backwards compatibility.
63
73
  key = ENV['WORKOS_API_KEY'] || ENV['WORKOS_KEY']
64
- WorkOS.key = key unless key.nil?
74
+ config.key = key unless key.nil?
65
75
  end