workos 2.1.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.semaphore/semaphore.yml +13 -39
- data/Gemfile.lock +2 -2
- data/README.md +4 -0
- data/lib/workos/audit_trail.rb +1 -0
- data/lib/workos/challenge.rb +55 -0
- data/lib/workos/client.rb +2 -0
- data/lib/workos/connection.rb +1 -0
- data/lib/workos/deprecated_hash_wrapper.rb +76 -0
- data/lib/workos/directory.rb +1 -0
- data/lib/workos/directory_group.rb +22 -2
- data/lib/workos/directory_sync.rb +12 -8
- data/lib/workos/directory_user.rb +9 -1
- data/lib/workos/errors.rb +3 -1
- data/lib/workos/factor.rb +54 -0
- data/lib/workos/hash_provider.rb +19 -0
- data/lib/workos/mfa.rb +165 -0
- data/lib/workos/organization.rb +1 -0
- data/lib/workos/organizations.rb +1 -0
- data/lib/workos/profile.rb +1 -0
- data/lib/workos/profile_and_token.rb +1 -0
- data/lib/workos/sso.rb +1 -0
- data/lib/workos/types/challenge_struct.rb +18 -0
- data/lib/workos/types/directory_group_struct.rb +5 -0
- data/lib/workos/types/factor_struct.rb +18 -0
- data/lib/workos/types/passwordless_session_struct.rb +2 -0
- data/lib/workos/types/verify_factor_struct.rb +13 -0
- data/lib/workos/types.rb +3 -0
- data/lib/workos/verify_factor.rb +40 -0
- data/lib/workos/version.rb +1 -1
- data/lib/workos/webhook.rb +1 -0
- data/lib/workos/webhooks.rb +1 -1
- data/lib/workos.rb +7 -0
- data/spec/lib/workos/directory_sync_spec.rb +26 -18
- data/spec/lib/workos/directory_user_spec.rb +36 -0
- data/spec/lib/workos/mfa_spec.rb +262 -0
- data/spec/lib/workos/sso_spec.rb +0 -2
- data/spec/support/fixtures/vcr_cassettes/directory_sync/get_group.yml +48 -28
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +46 -32
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +47 -31
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +46 -34
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +41 -31
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_no_options.yml +36 -26
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +38 -28
- data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_generic_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_sms_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/challenge_factor_totp_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/delete_factor.yml +80 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_generic_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_sms_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/enroll_factor_totp_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_invalid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/get_factor_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/verify_factor_generic_expired.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/verify_factor_generic_invalid.yml +84 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/verify_factor_generic_valid.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/mfa/verify_factor_generic_valid_is_false.yml +82 -0
- metadata +42 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7abb4f1d075ea976bbc8577247d36ff763a21dd1b18335daac39a8c80d6acea
|
4
|
+
data.tar.gz: 4c8e6326e7b80773a292754a7030033773470dc12228571cad8b0198a3c8342b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d4c51f21848cb44e0f0326deab050040989811f829b4bbf1c317aca9d08e113c47bd4dbd822faac3f195d8695204fd3acb9a797638a0d9c4f951100964a53e7
|
7
|
+
data.tar.gz: 2b25fd19c5008c27d03a9ab73f6dcb02ba2cd7f133d0726ce46ccadb4928e2805dca1f63dbefd9552ea7ee8ea9acf122a7641dabf48e5199f4f607dcb8754c46
|
data/.semaphore/semaphore.yml
CHANGED
@@ -31,45 +31,19 @@ blocks:
|
|
31
31
|
- name: codecov-workos-ruby
|
32
32
|
jobs:
|
33
33
|
- name: Ruby 1.9.3
|
34
|
-
|
35
|
-
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
- checkout
|
48
|
-
- sem-version ruby 2.3.4
|
49
|
-
- bundle install
|
50
|
-
- bundle exec rspec
|
51
|
-
- name: Ruby 2.5.7
|
52
|
-
commands:
|
53
|
-
- checkout
|
54
|
-
- sem-version ruby 2.5.7
|
55
|
-
- bundle install
|
56
|
-
- bundle exec rspec
|
57
|
-
- name: Ruby 2.6.5
|
58
|
-
commands:
|
59
|
-
- checkout
|
60
|
-
- sem-version ruby 2.6.5
|
61
|
-
- bundle install
|
62
|
-
- bundle exec rspec
|
63
|
-
- name: Ruby 2.7.3
|
64
|
-
commands:
|
65
|
-
- checkout
|
66
|
-
- sem-version ruby 2.7.3
|
67
|
-
- bundle install
|
68
|
-
- bundle exec rspec
|
69
|
-
- name: Ruby 3.0.2
|
70
|
-
commands:
|
71
|
-
- checkout
|
72
|
-
- sem-version ruby 3.0.2
|
34
|
+
matrix:
|
35
|
+
- env_var: RUBY_VERSION
|
36
|
+
values:
|
37
|
+
- 1.9.3-p551
|
38
|
+
- 2.0.0-p648
|
39
|
+
- 2.3.4
|
40
|
+
- 2.5.7
|
41
|
+
- 2.6.5
|
42
|
+
- 2.7.3
|
43
|
+
- 3.0.2
|
44
|
+
commands:
|
45
|
+
- checkout
|
46
|
+
- sem-version ruby $RUBY_VERSION
|
73
47
|
- bundle install
|
74
48
|
- bundle exec rspec
|
75
49
|
promotions:
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
workos (2.
|
4
|
+
workos (2.3.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.
|
63
|
+
sorbet-runtime (0.5.10090)
|
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
@@ -38,6 +38,10 @@ Or, you may set the key yourself, such as in an initializer in your application
|
|
38
38
|
WorkOS.key = '[your api key]'
|
39
39
|
```
|
40
40
|
|
41
|
+
## SDK Versioning
|
42
|
+
|
43
|
+
For our SDKs WorkOS follows a Semantic Versioning ([SemVer](https://semver.org/)) process where all releases will have a version X.Y.Z (like 1.0.0) pattern wherein Z would be a bug fix (e.g., 1.0.1), Y would be a minor release (1.1.0) and X would be a major release (2.0.0). We permit any breaking changes to only be released in major versions and strongly recommend reading changelogs before making any major version upgrades.
|
44
|
+
|
41
45
|
## More Information
|
42
46
|
|
43
47
|
* [Single Sign-On Guide](https://workos.com/docs/sso/guide)
|
data/lib/workos/audit_trail.rb
CHANGED
@@ -65,6 +65,7 @@ module WorkOS
|
|
65
65
|
# @option options [String] before Event ID to look before
|
66
66
|
# @option options [String] after Event ID to look after
|
67
67
|
# @option options [Integer] limit Number of Events to return
|
68
|
+
# @option options [String] order The order in which to paginate records
|
68
69
|
# @option options [Array<String>] group List of Groups to filter for
|
69
70
|
# @option options [Array<String>] action List of Actions to filter for
|
70
71
|
# @option options [Array<String>] action_type List of Action Types to
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: false
|
3
|
+
|
4
|
+
module WorkOS
|
5
|
+
# The Challnge 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 Challenge
|
9
|
+
include HashProvider
|
10
|
+
extend T::Sig
|
11
|
+
|
12
|
+
attr_accessor :id, :object, :expires_at, :code, :authentication_factor_id, :updated_at, :created_at
|
13
|
+
|
14
|
+
sig { params(json: String).void }
|
15
|
+
def initialize(json)
|
16
|
+
raw = parse_json(json)
|
17
|
+
@id = T.let(raw.id, String)
|
18
|
+
@object = T.let(raw.object, String)
|
19
|
+
@expires_at = T.let(raw.expires_at, String)
|
20
|
+
@code = raw.code
|
21
|
+
@authentication_factor_id = T.let(raw.authentication_factor_id, String)
|
22
|
+
@created_at = T.let(raw.created_at, String)
|
23
|
+
@updated_at = T.let(raw.updated_at, String)
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json(*)
|
27
|
+
{
|
28
|
+
id: id,
|
29
|
+
object: object,
|
30
|
+
expires_at: expires_at,
|
31
|
+
code: code,
|
32
|
+
authentication_factor_id: authentication_factor_id,
|
33
|
+
created_at: created_at,
|
34
|
+
updated_at: updated_at,
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
sig { params(json_string: String).returns(WorkOS::Types::ChallengeStruct) }
|
41
|
+
def parse_json(json_string)
|
42
|
+
hash = JSON.parse(json_string, symbolize_names: true)
|
43
|
+
|
44
|
+
WorkOS::Types::ChallengeStruct.new(
|
45
|
+
id: hash[:id],
|
46
|
+
object: hash[:object],
|
47
|
+
expires_at: hash[:expires_at],
|
48
|
+
code: hash[:code],
|
49
|
+
authentication_factor_id: hash[:authentication_factor_id],
|
50
|
+
created_at: hash[:created_at],
|
51
|
+
updated_at: hash[:updated_at],
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/workos/client.rb
CHANGED
@@ -144,6 +144,7 @@ module WorkOS
|
|
144
144
|
)
|
145
145
|
when 422
|
146
146
|
message = json['message']
|
147
|
+
code = json['code']
|
147
148
|
errors = extract_error(json['errors']) if json['errors']
|
148
149
|
message += " (#{errors})" if errors
|
149
150
|
|
@@ -151,6 +152,7 @@ module WorkOS
|
|
151
152
|
message: message,
|
152
153
|
http_status: http_status,
|
153
154
|
request_id: response['x-request-id'],
|
155
|
+
code: code,
|
154
156
|
)
|
155
157
|
end
|
156
158
|
end
|
data/lib/workos/connection.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WorkOS
|
4
|
+
# A Temporary wrapper class for a Hash, currently the base class for
|
5
|
+
# WorOS::DirectoryGroup and WorkOS::DirectoryUser. Makes all the Hash
|
6
|
+
# methods available to those classes, but will also emit a deprecation
|
7
|
+
# warning whenever any of them are used.
|
8
|
+
#
|
9
|
+
# Once we deprecate Hash compatibility, this model can be deleted.
|
10
|
+
class DeprecatedHashWrapper < Hash
|
11
|
+
(public_instance_methods - Object.methods).each do |method_name|
|
12
|
+
define_method method_name do |*args, &block|
|
13
|
+
print_deprecation_warning(method_name)
|
14
|
+
super(*args, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# call the original implementation of :replace in Hash,
|
19
|
+
# so we don't show the deprecation warning
|
20
|
+
def replace_without_warning(new_hash)
|
21
|
+
method(:replace).super_method&.call(new_hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](attribute_name)
|
25
|
+
usage = "#{object_name}.#{attribute_name}"
|
26
|
+
warning_message = "WARNING: The Hash style access for #{class_name} attributes is deprecated
|
27
|
+
and will be removed in a future version. Please use `#{usage}` or equivalent accessor.\n"
|
28
|
+
|
29
|
+
print_deprecation_warning('[]', warning_message)
|
30
|
+
|
31
|
+
super(attribute_name.to_sym)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def deprecation_warning(method_name)
|
37
|
+
usage = "#{object_name}.to_h.#{method_name}"
|
38
|
+
|
39
|
+
"WARNING: Hash compatibility for #{class_name} is deprecated and will be removed
|
40
|
+
in a future version. Please use `#{usage}` to access methods on the attribute Hash object.\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def print_deprecation_warning(method_name, warning_message = deprecation_warning(method_name))
|
44
|
+
if RUBY_VERSION > '3'
|
45
|
+
warn warning_message, category: :deprecated
|
46
|
+
else
|
47
|
+
warn warning_message
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def class_name
|
52
|
+
self.class.name
|
53
|
+
end
|
54
|
+
|
55
|
+
# We want to do class_name.demodulize.underscore here, but that's not available in Ruby 1.9, so
|
56
|
+
# implementing the demodulize and underscore methods here.
|
57
|
+
def object_name
|
58
|
+
i = class_name.rindex('::')
|
59
|
+
object_name = i ? class_name[(i + 2)..-1] : class_name
|
60
|
+
underscore(object_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def underscore(camel_cased_word)
|
64
|
+
return camel_cased_word.to_s unless /[A-Z-]|::/.match?(camel_cased_word)
|
65
|
+
|
66
|
+
word = camel_cased_word.to_s.gsub('::', '/')
|
67
|
+
word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?=a)b)(?=\b|[^a-z])/) do
|
68
|
+
"#{Regexp.last_match(1) && '_'}#{Regexp.last_match(2).downcase}"
|
69
|
+
end
|
70
|
+
word.gsub!(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) { (Regexp.last_match(1) || Regexp.last_match(2)) << '_' }
|
71
|
+
word.tr!('-', '_')
|
72
|
+
word.downcase!
|
73
|
+
word
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/workos/directory.rb
CHANGED
@@ -6,6 +6,7 @@ module WorkOS
|
|
6
6
|
# a WorkOS Directory resource. This class is not meant to be instantiated
|
7
7
|
# in user space, and is instantiated internally but exposed.
|
8
8
|
class Directory
|
9
|
+
include HashProvider
|
9
10
|
extend T::Sig
|
10
11
|
|
11
12
|
attr_accessor :id, :domain, :name, :type, :state, :organization_id, :created_at, :updated_at
|
@@ -5,23 +5,38 @@ module WorkOS
|
|
5
5
|
# The DirectoryGroup class provides a lightweight wrapper around
|
6
6
|
# a WorkOS DirectoryGroup resource. This class is not meant to be instantiated
|
7
7
|
# in user space, and is instantiated internally but exposed.
|
8
|
-
class DirectoryGroup
|
8
|
+
class DirectoryGroup < DeprecatedHashWrapper
|
9
|
+
include HashProvider
|
9
10
|
extend T::Sig
|
10
11
|
|
11
|
-
attr_accessor :id, :name
|
12
|
+
attr_accessor :id, :directory_id, :idp_id, :name, :created_at, :updated_at, :raw_attributes
|
12
13
|
|
14
|
+
# rubocop:disable Metrics/AbcSize
|
13
15
|
sig { params(json: String).void }
|
14
16
|
def initialize(json)
|
15
17
|
raw = parse_json(json)
|
16
18
|
|
17
19
|
@id = T.let(raw.id, String)
|
20
|
+
@directory_id = T.let(raw.directory_id, String)
|
21
|
+
@idp_id = T.let(raw.idp_id, String)
|
18
22
|
@name = T.let(raw.name, String)
|
23
|
+
@created_at = T.let(raw.created_at, String)
|
24
|
+
@updated_at = T.let(raw.updated_at, String)
|
25
|
+
@raw_attributes = raw.raw_attributes
|
26
|
+
|
27
|
+
replace_without_warning(to_json)
|
19
28
|
end
|
29
|
+
# rubocop:enable Metrics/AbcSize
|
20
30
|
|
21
31
|
def to_json(*)
|
22
32
|
{
|
23
33
|
id: id,
|
34
|
+
directory_id: directory_id,
|
35
|
+
idp_id: idp_id,
|
24
36
|
name: name,
|
37
|
+
created_at: created_at,
|
38
|
+
updated_at: updated_at,
|
39
|
+
raw_attributes: raw_attributes,
|
25
40
|
}
|
26
41
|
end
|
27
42
|
|
@@ -37,7 +52,12 @@ module WorkOS
|
|
37
52
|
|
38
53
|
WorkOS::Types::DirectoryGroupStruct.new(
|
39
54
|
id: hash[:id],
|
55
|
+
directory_id: hash[:directory_id],
|
56
|
+
idp_id: hash[:idp_id],
|
40
57
|
name: hash[:name],
|
58
|
+
created_at: hash[:created_at],
|
59
|
+
updated_at: hash[:updated_at],
|
60
|
+
raw_attributes: hash[:raw_attributes],
|
41
61
|
)
|
42
62
|
end
|
43
63
|
end
|
@@ -22,10 +22,12 @@ module WorkOS
|
|
22
22
|
# retrieved.
|
23
23
|
# @option options [String] search A search term for direcory names.
|
24
24
|
# @option options [String] limit Maximum number of records to return.
|
25
|
+
# @option options [String] order The order in which to paginate records
|
25
26
|
# @option options [String] before Pagination cursor to receive records
|
26
27
|
# before a provided Directory ID.
|
27
28
|
# @option options [String] after Pagination cursor to receive records
|
28
29
|
# before a provided Directory ID.
|
30
|
+
# @option options [String] organization_id The ID for an Organization configured on WorkOS.
|
29
31
|
#
|
30
32
|
# @return [Hash]
|
31
33
|
sig do
|
@@ -90,12 +92,13 @@ module WorkOS
|
|
90
92
|
# @option options [String] user The ID of the directory user whose
|
91
93
|
# directory groups will be retrieved.
|
92
94
|
# @option options [String] limit Maximum number of records to return.
|
95
|
+
# @option options [String] order The order in which to paginate records
|
93
96
|
# @option options [String] before Pagination cursor to receive records
|
94
97
|
# before a provided Directory Group ID.
|
95
98
|
# @option options [String] after Pagination cursor to receive records
|
96
99
|
# before a provided Directory Group ID.
|
97
100
|
#
|
98
|
-
# @return [
|
101
|
+
# @return [WorkOS::DirectoryGroup]
|
99
102
|
sig do
|
100
103
|
params(
|
101
104
|
options: T::Hash[Symbol, String],
|
@@ -129,12 +132,13 @@ module WorkOS
|
|
129
132
|
# @option options [String] user The ID of the directory group whose
|
130
133
|
# directory users will be retrieved.
|
131
134
|
# @option options [String] limit Maximum number of records to return.
|
135
|
+
# @option options [String] order The order in which to paginate records
|
132
136
|
# @option options [String] before Pagination cursor to receive records
|
133
137
|
# before a provided Directory User ID.
|
134
138
|
# @option options [String] after Pagination cursor to receive records
|
135
139
|
# before a provided Directory User ID.
|
136
140
|
#
|
137
|
-
# @return [
|
141
|
+
# @return [WorkOS::DirectoryUser]
|
138
142
|
sig do
|
139
143
|
params(
|
140
144
|
options: T::Hash[Symbol, String],
|
@@ -164,8 +168,8 @@ module WorkOS
|
|
164
168
|
#
|
165
169
|
# @param [String] id The ID of the directory group.
|
166
170
|
#
|
167
|
-
# @return
|
168
|
-
sig { params(id: String).returns(
|
171
|
+
# @return WorkOS::DirectoryGroup
|
172
|
+
sig { params(id: String).returns(WorkOS::DirectoryGroup) }
|
169
173
|
def get_group(id)
|
170
174
|
response = execute_request(
|
171
175
|
request: get_request(
|
@@ -174,15 +178,15 @@ module WorkOS
|
|
174
178
|
),
|
175
179
|
)
|
176
180
|
|
177
|
-
|
181
|
+
::WorkOS::DirectoryGroup.new(response.body)
|
178
182
|
end
|
179
183
|
|
180
184
|
# Retrieve the directory user with the given ID.
|
181
185
|
#
|
182
186
|
# @param [String] id The ID of the directory user.
|
183
187
|
#
|
184
|
-
# @return
|
185
|
-
sig { params(id: String).returns(
|
188
|
+
# @return WorkOS::DirectoryUser
|
189
|
+
sig { params(id: String).returns(WorkOS::DirectoryUser) }
|
186
190
|
def get_user(id)
|
187
191
|
response = execute_request(
|
188
192
|
request: get_request(
|
@@ -191,7 +195,7 @@ module WorkOS
|
|
191
195
|
),
|
192
196
|
)
|
193
197
|
|
194
|
-
|
198
|
+
::WorkOS::DirectoryUser.new(response.body)
|
195
199
|
end
|
196
200
|
|
197
201
|
# Delete the directory with the given ID.
|
@@ -5,7 +5,8 @@ module WorkOS
|
|
5
5
|
# The DirectoryUser class provides a lightweight wrapper around
|
6
6
|
# a WorkOS DirectoryUser resource. This class is not meant to be instantiated
|
7
7
|
# in DirectoryUser space, and is instantiated internally but exposed.
|
8
|
-
class DirectoryUser
|
8
|
+
class DirectoryUser < DeprecatedHashWrapper
|
9
|
+
include HashProvider
|
9
10
|
extend T::Sig
|
10
11
|
|
11
12
|
attr_accessor :id, :idp_id, :emails, :first_name, :last_name, :username, :state,
|
@@ -26,6 +27,8 @@ module WorkOS
|
|
26
27
|
@groups = T.let(raw.groups, Array)
|
27
28
|
@custom_attributes = raw.custom_attributes
|
28
29
|
@raw_attributes = raw.raw_attributes
|
30
|
+
|
31
|
+
replace_without_warning(to_json)
|
29
32
|
end
|
30
33
|
# rubocop:enable Metrics/AbcSize
|
31
34
|
|
@@ -44,6 +47,11 @@ module WorkOS
|
|
44
47
|
}
|
45
48
|
end
|
46
49
|
|
50
|
+
def primary_email
|
51
|
+
primary_email = (emails || []).find { |email| email[:primary] }
|
52
|
+
return primary_email[:value] if primary_email
|
53
|
+
end
|
54
|
+
|
47
55
|
private
|
48
56
|
|
49
57
|
sig do
|
data/lib/workos/errors.rb
CHANGED
@@ -17,14 +17,16 @@ module WorkOS
|
|
17
17
|
error_description: T.nilable(String),
|
18
18
|
http_status: T.nilable(Integer),
|
19
19
|
request_id: T.nilable(String),
|
20
|
+
code: T.nilable(String),
|
20
21
|
).void
|
21
22
|
end
|
22
|
-
def initialize(message: nil, error: nil, error_description: nil, http_status: nil, request_id: nil)
|
23
|
+
def initialize(message: nil, error: nil, error_description: nil, http_status: nil, request_id: nil, code: nil)
|
23
24
|
@message = message
|
24
25
|
@error = error
|
25
26
|
@error_description = error_description
|
26
27
|
@http_status = http_status
|
27
28
|
@request_id = request_id
|
29
|
+
@code = code
|
28
30
|
end
|
29
31
|
|
30
32
|
sig { returns(String) }
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: false
|
3
|
+
|
4
|
+
module WorkOS
|
5
|
+
# The Factor 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 Factor
|
9
|
+
include HashProvider
|
10
|
+
extend T::Sig
|
11
|
+
attr_accessor :id, :object, :type, :sms, :totp, :updated_at, :created_at
|
12
|
+
|
13
|
+
sig { params(json: String).void }
|
14
|
+
def initialize(json)
|
15
|
+
raw = parse_json(json)
|
16
|
+
@id = T.let(raw.id, String)
|
17
|
+
@object = T.let(raw.object, String)
|
18
|
+
@type = T.let(raw.type, String)
|
19
|
+
@created_at = T.let(raw.created_at, String)
|
20
|
+
@updated_at = T.let(raw.updated_at, String)
|
21
|
+
@totp = raw.totp
|
22
|
+
@sms = raw.sms
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_json(*)
|
26
|
+
{
|
27
|
+
id: id,
|
28
|
+
object: object,
|
29
|
+
type: type,
|
30
|
+
totp: totp,
|
31
|
+
sms: sms,
|
32
|
+
created_at: created_at,
|
33
|
+
updated_at: updated_at,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
sig { params(json_string: String).returns(WorkOS::Types::FactorStruct) }
|
40
|
+
def parse_json(json_string)
|
41
|
+
hash = JSON.parse(json_string, symbolize_names: true)
|
42
|
+
|
43
|
+
WorkOS::Types::FactorStruct.new(
|
44
|
+
id: hash[:id],
|
45
|
+
object: hash[:object],
|
46
|
+
type: hash[:type],
|
47
|
+
totp: hash[:totp],
|
48
|
+
sms: hash[:sms],
|
49
|
+
created_at: hash[:created_at],
|
50
|
+
updated_at: hash[:updated_at],
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
module WorkOS
|
5
|
+
# Module to include an explicit method for converting a model into a Hash containing
|
6
|
+
# its attributes. Default implementation will simply call to_json. Individual classes
|
7
|
+
# may override.
|
8
|
+
module HashProvider
|
9
|
+
include Kernel
|
10
|
+
|
11
|
+
def to_json(*)
|
12
|
+
raise 'Must be implemented by including class.'
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
to_json
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|