workos 0.10.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/.semaphore/semaphore.yml +8 -2
- data/Gemfile.lock +49 -36
- data/LICENSE +1 -1
- data/README.md +13 -230
- data/lib/workos/client.rb +21 -4
- data/lib/workos/connection.rb +12 -1
- data/lib/workos/directory.rb +53 -0
- data/lib/workos/directory_group.rb +44 -0
- data/lib/workos/directory_sync.rb +63 -7
- data/lib/workos/directory_user.rb +63 -0
- data/lib/workos/organizations.rb +150 -0
- data/lib/workos/passwordless.rb +4 -0
- data/lib/workos/portal.rb +1 -81
- data/lib/workos/profile.rb +1 -2
- data/lib/workos/profile_and_token.rb +28 -0
- data/lib/workos/sso.rb +39 -104
- data/lib/workos/types/connection_struct.rb +3 -0
- data/lib/workos/types/directory_group_struct.rb +13 -0
- data/lib/workos/types/directory_struct.rb +16 -0
- data/lib/workos/types/directory_user_struct.rb +19 -0
- data/lib/workos/types/intent_enum.rb +1 -0
- data/lib/workos/types.rb +3 -0
- data/lib/workos/version.rb +1 -1
- data/lib/workos.rb +5 -0
- data/sorbet/rbi/gems/addressable.rbi +199 -0
- data/sorbet/rbi/gems/ast.rbi +49 -0
- data/sorbet/rbi/gems/codecov.rbi +37 -0
- data/sorbet/rbi/gems/crack.rbi +62 -0
- data/sorbet/rbi/gems/docile.rbi +36 -0
- data/sorbet/rbi/gems/hashdiff.rbi +66 -0
- data/sorbet/rbi/gems/parallel.rbi +83 -0
- data/sorbet/rbi/gems/parser.rbi +1429 -0
- data/sorbet/rbi/gems/public_suffix.rbi +104 -0
- data/sorbet/rbi/gems/rainbow.rbi +118 -0
- data/sorbet/rbi/gems/rake.rbi +644 -0
- data/sorbet/rbi/gems/regexp_parser.rbi +926 -0
- data/sorbet/rbi/gems/rexml.rbi +628 -0
- data/sorbet/rbi/gems/rspec-core.rbi +1898 -0
- data/sorbet/rbi/gems/rspec-expectations.rbi +1127 -0
- data/sorbet/rbi/gems/rspec-mocks.rbi +1099 -0
- data/sorbet/rbi/gems/rspec-support.rbi +280 -0
- data/sorbet/rbi/gems/rspec.rbi +15 -0
- data/sorbet/rbi/gems/rubocop-ast.rbi +1355 -0
- data/sorbet/rbi/gems/rubocop.rbi +7253 -0
- data/sorbet/rbi/gems/ruby-progressbar.rbi +304 -0
- data/sorbet/rbi/gems/simplecov-html.rbi +35 -0
- data/sorbet/rbi/gems/simplecov.rbi +406 -0
- data/sorbet/rbi/gems/unicode-display_width.rbi +17 -0
- data/sorbet/rbi/gems/vcr.rbi +572 -0
- data/sorbet/rbi/gems/webmock.rbi +556 -0
- data/sorbet/rbi/gems/yard.rbi +1165 -0
- data/sorbet/rbi/sorbet-typed/lib/rake/all/rake.rbi +645 -0
- data/sorbet/rbi/sorbet-typed/lib/rspec-core/all/rspec-core.rbi +1891 -0
- data/sorbet/rbi/sorbet-typed/lib/rubocop/~>0.85/rubocop.rbi +2072 -0
- data/sorbet/rbi/sorbet-typed/lib/yard/all/yard.rbi +1214 -0
- data/sorbet/rbi/todo.rbi +1 -3
- data/spec/lib/workos/audit_trail_spec.rb +0 -8
- data/spec/lib/workos/directory_sync_spec.rb +347 -40
- data/spec/lib/workos/organizations_spec.rb +164 -0
- data/spec/lib/workos/passwordless_spec.rb +0 -8
- data/spec/lib/workos/portal_spec.rb +17 -123
- data/spec/lib/workos/sso_spec.rb +144 -176
- data/spec/spec_helper.rb +2 -1
- data/spec/support/fixtures/vcr_cassettes/directory_sync/delete_directory.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/{sso/list_connections.yml → directory_sync/list_directories/with_after.yml} +7 -7
- data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_limit_param.yml → directory_sync/list_directories/with_before.yml} +8 -8
- data/spec/support/fixtures/vcr_cassettes/{sso/list_connections_with_connection_type_param.yml → directory_sync/list_directories/with_domain.yml} +11 -10
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_limit.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_directories.yml → list_directories/with_no_options.yml} +1 -1
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories/with_search.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_after.yml +76 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_before.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_directory.yml +78 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_limit.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_groups.yml → list_groups/with_no_options.yml} +16 -6
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups/with_user.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_after.yml +86 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_before.yml +75 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_directory.yml +93 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_group.yml +76 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users/with_limit.yml +75 -0
- data/spec/support/fixtures/vcr_cassettes/directory_sync/{list_users.yml → list_users/with_no_options.yml} +16 -6
- data/spec/support/fixtures/vcr_cassettes/organization/get.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/organization/get_invalid.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/organization/update.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/organization/update_invalid.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/portal/generate_link_dsync.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/portal/{generate_link.yml → generate_link_sso.yml} +1 -1
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_after.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_before.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_connection_type.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_domain_param.yml → list_connections/with_domain.yml} +6 -6
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_limit.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections/with_no_options.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/{list_connections_with_before_param.yml → list_connections/with_organization_id.yml} +7 -8
- data/workos.gemspec +2 -0
- metadata +113 -44
- data/sorbet/rbi/hidden-definitions/errors.txt +0 -24896
- data/sorbet/rbi/hidden-definitions/hidden.rbi +0 -38411
- data/sorbet/rbi/sorbet-typed/lib/bundler/all/bundler.rbi +0 -8684
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/gem.rbi +0 -4222
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/open3.rbi +0 -111
- data/sorbet/rbi/sorbet-typed/lib/ruby/all/resolv.rbi +0 -543
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories_with_domain_param.yml +0 -63
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_groups_with_directory_param.yml +0 -62
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_users_with_directory_param.yml +0 -62
- data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_invalid_source.yml +0 -58
- data/spec/support/fixtures/vcr_cassettes/sso/create_connection_with_valid_source.yml +0 -63
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_after_param.yml +0 -72
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# typed:
|
|
2
|
+
# typed: strict
|
|
3
3
|
|
|
4
4
|
require 'net/http'
|
|
5
5
|
|
|
@@ -21,12 +21,17 @@ module WorkOS
|
|
|
21
21
|
# @option options [String] domain The domain of the directory to be
|
|
22
22
|
# retrieved.
|
|
23
23
|
# @option options [String] search A search term for direcory names.
|
|
24
|
+
# @option options [String] limit Maximum number of records to return.
|
|
25
|
+
# @option options [String] before Pagination cursor to receive records
|
|
26
|
+
# before a provided Directory ID.
|
|
27
|
+
# @option options [String] after Pagination cursor to receive records
|
|
28
|
+
# before a provided Directory ID.
|
|
24
29
|
#
|
|
25
30
|
# @return [Hash]
|
|
26
31
|
sig do
|
|
27
32
|
params(
|
|
28
33
|
options: T::Hash[Symbol, String],
|
|
29
|
-
).returns(
|
|
34
|
+
).returns(WorkOS::Types::ListStruct)
|
|
30
35
|
end
|
|
31
36
|
def list_directories(options = {})
|
|
32
37
|
response = execute_request(
|
|
@@ -37,7 +42,15 @@ module WorkOS
|
|
|
37
42
|
),
|
|
38
43
|
)
|
|
39
44
|
|
|
40
|
-
JSON.parse(response.body)
|
|
45
|
+
parsed_response = JSON.parse(response.body)
|
|
46
|
+
directories = parsed_response['data'].map do |directory|
|
|
47
|
+
::WorkOS::Directory.new(directory.to_json)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
WorkOS::Types::ListStruct.new(
|
|
51
|
+
data: directories,
|
|
52
|
+
list_metadata: parsed_response['listMetadata'],
|
|
53
|
+
)
|
|
41
54
|
end
|
|
42
55
|
|
|
43
56
|
# Retrieve directory groups.
|
|
@@ -47,12 +60,17 @@ module WorkOS
|
|
|
47
60
|
# directory groups will be retrieved.
|
|
48
61
|
# @option options [String] user The ID of the directory user whose
|
|
49
62
|
# directory groups will be retrieved.
|
|
63
|
+
# @option options [String] limit Maximum number of records to return.
|
|
64
|
+
# @option options [String] before Pagination cursor to receive records
|
|
65
|
+
# before a provided Directory Group ID.
|
|
66
|
+
# @option options [String] after Pagination cursor to receive records
|
|
67
|
+
# before a provided Directory Group ID.
|
|
50
68
|
#
|
|
51
69
|
# @return [Hash]
|
|
52
70
|
sig do
|
|
53
71
|
params(
|
|
54
72
|
options: T::Hash[Symbol, String],
|
|
55
|
-
).returns(
|
|
73
|
+
).returns(WorkOS::Types::ListStruct)
|
|
56
74
|
end
|
|
57
75
|
def list_groups(options = {})
|
|
58
76
|
response = execute_request(
|
|
@@ -63,7 +81,15 @@ module WorkOS
|
|
|
63
81
|
),
|
|
64
82
|
)
|
|
65
83
|
|
|
66
|
-
JSON.parse(response.body)
|
|
84
|
+
parsed_response = JSON.parse(response.body)
|
|
85
|
+
groups = parsed_response['data'].map do |group|
|
|
86
|
+
::WorkOS::DirectoryGroup.new(group.to_json)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
WorkOS::Types::ListStruct.new(
|
|
90
|
+
data: groups,
|
|
91
|
+
list_metadata: parsed_response['listMetadata'],
|
|
92
|
+
)
|
|
67
93
|
end
|
|
68
94
|
|
|
69
95
|
# Retrieve directory users.
|
|
@@ -73,12 +99,17 @@ module WorkOS
|
|
|
73
99
|
# directory users will be retrieved.
|
|
74
100
|
# @option options [String] user The ID of the directory group whose
|
|
75
101
|
# directory users will be retrieved.
|
|
102
|
+
# @option options [String] limit Maximum number of records to return.
|
|
103
|
+
# @option options [String] before Pagination cursor to receive records
|
|
104
|
+
# before a provided Directory User ID.
|
|
105
|
+
# @option options [String] after Pagination cursor to receive records
|
|
106
|
+
# before a provided Directory User ID.
|
|
76
107
|
#
|
|
77
108
|
# @return [Hash]
|
|
78
109
|
sig do
|
|
79
110
|
params(
|
|
80
111
|
options: T::Hash[Symbol, String],
|
|
81
|
-
).returns(
|
|
112
|
+
).returns(WorkOS::Types::ListStruct)
|
|
82
113
|
end
|
|
83
114
|
def list_users(options = {})
|
|
84
115
|
response = execute_request(
|
|
@@ -89,7 +120,15 @@ module WorkOS
|
|
|
89
120
|
),
|
|
90
121
|
)
|
|
91
122
|
|
|
92
|
-
JSON.parse(response.body)
|
|
123
|
+
parsed_response = JSON.parse(response.body)
|
|
124
|
+
users = parsed_response['data'].map do |user|
|
|
125
|
+
::WorkOS::DirectoryUser.new(user.to_json)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
WorkOS::Types::ListStruct.new(
|
|
129
|
+
data: users,
|
|
130
|
+
list_metadata: parsed_response['listMetadata'],
|
|
131
|
+
)
|
|
93
132
|
end
|
|
94
133
|
|
|
95
134
|
# Retrieve the directory group with the given ID.
|
|
@@ -125,6 +164,23 @@ module WorkOS
|
|
|
125
164
|
|
|
126
165
|
JSON.parse(response.body)
|
|
127
166
|
end
|
|
167
|
+
|
|
168
|
+
# Delete the directory with the given ID.
|
|
169
|
+
#
|
|
170
|
+
# @param [String] id The ID of the directory.
|
|
171
|
+
#
|
|
172
|
+
# @return Boolean
|
|
173
|
+
sig { params(id: String).returns(T::Boolean) }
|
|
174
|
+
def delete_directory(id)
|
|
175
|
+
request = delete_request(
|
|
176
|
+
auth: true,
|
|
177
|
+
path: "/directories/#{id}",
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
response = execute_request(request: request)
|
|
181
|
+
|
|
182
|
+
response.is_a? Net::HTTPSuccess
|
|
183
|
+
end
|
|
128
184
|
end
|
|
129
185
|
end
|
|
130
186
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
3
|
+
|
|
4
|
+
module WorkOS
|
|
5
|
+
# The DirectoryUser 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 DirectoryUser
|
|
9
|
+
extend T::Sig
|
|
10
|
+
|
|
11
|
+
attr_accessor :id, :idp_id, :emails, :first_name, :last_name, :username, :state,
|
|
12
|
+
:raw_attributes
|
|
13
|
+
|
|
14
|
+
sig { params(json: String).void }
|
|
15
|
+
def initialize(json)
|
|
16
|
+
raw = parse_json(json)
|
|
17
|
+
|
|
18
|
+
@id = T.let(raw.id, String)
|
|
19
|
+
@idp_id = T.let(raw.idp_id, String)
|
|
20
|
+
@emails = T.let(raw.emails, Array)
|
|
21
|
+
@first_name = raw.first_name
|
|
22
|
+
@last_name = raw.last_name
|
|
23
|
+
@username = raw.username
|
|
24
|
+
@state = raw.state
|
|
25
|
+
@raw_attributes = raw.raw_attributes
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def to_json(*)
|
|
29
|
+
{
|
|
30
|
+
id: id,
|
|
31
|
+
idp_id: idp_id,
|
|
32
|
+
emails: emails,
|
|
33
|
+
first_name: first_name,
|
|
34
|
+
last_name: last_name,
|
|
35
|
+
username: username,
|
|
36
|
+
state: state,
|
|
37
|
+
raw_attributes: raw_attributes,
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
sig do
|
|
44
|
+
params(
|
|
45
|
+
json_string: String,
|
|
46
|
+
).returns(WorkOS::Types::DirectoryUserStruct)
|
|
47
|
+
end
|
|
48
|
+
def parse_json(json_string)
|
|
49
|
+
hash = JSON.parse(json_string, symbolize_names: true)
|
|
50
|
+
|
|
51
|
+
WorkOS::Types::DirectoryUserStruct.new(
|
|
52
|
+
id: hash[:id],
|
|
53
|
+
idp_id: hash[:idp_id],
|
|
54
|
+
emails: hash[:emails],
|
|
55
|
+
first_name: hash[:first_name],
|
|
56
|
+
last_name: hash[:last_name],
|
|
57
|
+
username: hash[:username],
|
|
58
|
+
state: hash[:state],
|
|
59
|
+
raw_attributes: hash[:raw_attributes],
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
3
|
+
|
|
4
|
+
require 'net/http'
|
|
5
|
+
|
|
6
|
+
module WorkOS
|
|
7
|
+
# The Organizations module provides resource methods for working with Organizations
|
|
8
|
+
module Organizations
|
|
9
|
+
class << self
|
|
10
|
+
extend T::Sig
|
|
11
|
+
include Base
|
|
12
|
+
include Client
|
|
13
|
+
|
|
14
|
+
# Retrieve a list of organizations that have connections configured
|
|
15
|
+
# within your WorkOS dashboard.
|
|
16
|
+
#
|
|
17
|
+
# @param [Array<String>] domains Filter organizations to only return those
|
|
18
|
+
# that are associated with the provided domains.
|
|
19
|
+
# @param [String] before A pagination argument used to request
|
|
20
|
+
# organizations before the provided Organization ID.
|
|
21
|
+
# @param [String] after A pagination argument used to request
|
|
22
|
+
# organizations after the provided Organization ID.
|
|
23
|
+
# @param [Integer] limit A pagination argument used to limit the number
|
|
24
|
+
# of listed Organizations that are returned.
|
|
25
|
+
sig do
|
|
26
|
+
params(
|
|
27
|
+
options: T::Hash[Symbol, String],
|
|
28
|
+
).returns(WorkOS::Types::ListStruct)
|
|
29
|
+
end
|
|
30
|
+
def list_organizations(options = {})
|
|
31
|
+
response = execute_request(
|
|
32
|
+
request: get_request(
|
|
33
|
+
path: '/organizations',
|
|
34
|
+
auth: true,
|
|
35
|
+
params: options,
|
|
36
|
+
),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
parsed_response = JSON.parse(response.body)
|
|
40
|
+
|
|
41
|
+
organizations = parsed_response['data'].map do |organization|
|
|
42
|
+
::WorkOS::Organization.new(organization.to_json)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
WorkOS::Types::ListStruct.new(
|
|
46
|
+
data: organizations,
|
|
47
|
+
list_metadata: parsed_response['listMetadata'],
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Get an Organization
|
|
52
|
+
#
|
|
53
|
+
# @param [String] id Organization unique identifier
|
|
54
|
+
#
|
|
55
|
+
# @example
|
|
56
|
+
# WorkOS::Portal.get_organization(id: 'org_02DRA1XNSJDZ19A31F183ECQW9')
|
|
57
|
+
# => #<WorkOS::Organization:0x00007fb6e4193d20
|
|
58
|
+
# @id="org_02DRA1XNSJDZ19A31F183ECQW9",
|
|
59
|
+
# @name="Foo Corp",
|
|
60
|
+
# @domains=
|
|
61
|
+
# [{:object=>"organization_domain",
|
|
62
|
+
# :id=>"org_domain_01E6PK9N3XMD8RHWF7S66380AR",
|
|
63
|
+
# :domain=>"foo-corp.com"}]>
|
|
64
|
+
#
|
|
65
|
+
# @return [WorkOS::Connection]
|
|
66
|
+
sig { params(id: String).returns(WorkOS::Organization) }
|
|
67
|
+
def get_organization(id:)
|
|
68
|
+
request = get_request(
|
|
69
|
+
auth: true,
|
|
70
|
+
path: "/organizations/#{id}",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
response = execute_request(request: request)
|
|
74
|
+
|
|
75
|
+
WorkOS::Organization.new(response.body)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Create an organization
|
|
79
|
+
#
|
|
80
|
+
# @param [Array<String>] domains List of domains that belong to the
|
|
81
|
+
# organization
|
|
82
|
+
# @param [String] name A unique, descriptive name for the organization
|
|
83
|
+
sig do
|
|
84
|
+
params(
|
|
85
|
+
domains: T::Array[String],
|
|
86
|
+
name: String,
|
|
87
|
+
).returns(WorkOS::Organization)
|
|
88
|
+
end
|
|
89
|
+
def create_organization(domains:, name:)
|
|
90
|
+
request = post_request(
|
|
91
|
+
auth: true,
|
|
92
|
+
body: { domains: domains, name: name },
|
|
93
|
+
path: '/organizations',
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
response = execute_request(request: request)
|
|
97
|
+
check_and_raise_organization_error(response: response)
|
|
98
|
+
|
|
99
|
+
WorkOS::Organization.new(response.body)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Update an organization
|
|
103
|
+
#
|
|
104
|
+
# @param [String] organization Organization unique identifier
|
|
105
|
+
# @param [Array<String>] domains List of domains that belong to the
|
|
106
|
+
# organization
|
|
107
|
+
# @param [String] name A unique, descriptive name for the organization
|
|
108
|
+
sig do
|
|
109
|
+
params(
|
|
110
|
+
organization: String,
|
|
111
|
+
domains: T::Array[String],
|
|
112
|
+
name: String,
|
|
113
|
+
).returns(WorkOS::Organization)
|
|
114
|
+
end
|
|
115
|
+
def update_organization(organization:, domains:, name:)
|
|
116
|
+
request = put_request(
|
|
117
|
+
auth: true,
|
|
118
|
+
body: { domains: domains, name: name },
|
|
119
|
+
path: "/organizations/#{organization}",
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
response = execute_request(request: request)
|
|
123
|
+
check_and_raise_organization_error(response: response)
|
|
124
|
+
|
|
125
|
+
WorkOS::Organization.new(response.body)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
private
|
|
129
|
+
|
|
130
|
+
sig { params(response: Net::HTTPResponse).void }
|
|
131
|
+
def check_and_raise_organization_error(response:)
|
|
132
|
+
begin
|
|
133
|
+
body = JSON.parse(response.body)
|
|
134
|
+
return unless body['message']
|
|
135
|
+
|
|
136
|
+
message = body['message']
|
|
137
|
+
request_id = response['x-request-id']
|
|
138
|
+
rescue StandardError
|
|
139
|
+
message = 'Something went wrong'
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
raise APIError.new(
|
|
143
|
+
message: message,
|
|
144
|
+
http_status: nil,
|
|
145
|
+
request_id: request_id,
|
|
146
|
+
)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
data/lib/workos/passwordless.rb
CHANGED
|
@@ -23,6 +23,10 @@ module WorkOS
|
|
|
23
23
|
# received from WorkOS will contain. The state parameter can be used to
|
|
24
24
|
# encode arbitrary information to help restore application state between
|
|
25
25
|
# redirects.
|
|
26
|
+
# @option options [String] connection Optional parameter for the ID of a
|
|
27
|
+
# specific connection. This can be used to create a Passwordless Session
|
|
28
|
+
# for a specific connection rather than using the domain from the email
|
|
29
|
+
# to determine the Organization and Connection.
|
|
26
30
|
# @option options [String] type The type of Passwordless Session to
|
|
27
31
|
# create. Currently, the only supported value is 'MagicLink'.
|
|
28
32
|
# @option options [String] redirect_uri The URI where users are directed
|
data/lib/workos/portal.rb
CHANGED
|
@@ -15,34 +15,10 @@ module WorkOS
|
|
|
15
15
|
GENERATE_LINK_INTENTS = WorkOS::Types::Intent.values.map(&:serialize).
|
|
16
16
|
freeze
|
|
17
17
|
|
|
18
|
-
# Create an organization
|
|
19
|
-
#
|
|
20
|
-
# @param [Array<String>] domains List of domains that belong to the
|
|
21
|
-
# organization
|
|
22
|
-
# @param [String] name A unique, descriptive name for the organization
|
|
23
|
-
sig do
|
|
24
|
-
params(
|
|
25
|
-
domains: T::Array[String],
|
|
26
|
-
name: String,
|
|
27
|
-
).returns(WorkOS::Organization)
|
|
28
|
-
end
|
|
29
|
-
def create_organization(domains:, name:)
|
|
30
|
-
request = post_request(
|
|
31
|
-
auth: true,
|
|
32
|
-
body: { domains: domains, name: name },
|
|
33
|
-
path: '/organizations',
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
response = execute_request(request: request)
|
|
37
|
-
check_and_raise_organization_error(response: response)
|
|
38
|
-
|
|
39
|
-
WorkOS::Organization.new(response.body)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
18
|
# Generate a link to grant access to an organization's Admin Portal
|
|
43
19
|
#
|
|
44
20
|
# @param [String] intent The access scope for the generated Admin Portal
|
|
45
|
-
# link. Valid values are: ["sso"]
|
|
21
|
+
# link. Valid values are: ["sso", "dsync"]
|
|
46
22
|
# @param [String] organization The ID of the organization the Admin
|
|
47
23
|
# Portal link will be generated for.
|
|
48
24
|
# @param [String] The URL that the end user will be redirected to upon
|
|
@@ -73,64 +49,8 @@ module WorkOS
|
|
|
73
49
|
JSON.parse(response.body)['link']
|
|
74
50
|
end
|
|
75
51
|
|
|
76
|
-
# Retrieve a list of organizations that have connections configured
|
|
77
|
-
# within your WorkOS dashboard.
|
|
78
|
-
#
|
|
79
|
-
# @param [Array<String>] domains Filter organizations to only return those
|
|
80
|
-
# that are associated with the provided domains.
|
|
81
|
-
# @param [String] before A pagination argument used to request
|
|
82
|
-
# organizations before the provided Organization ID.
|
|
83
|
-
# @param [String] after A pagination argument used to request
|
|
84
|
-
# organizations after the provided Organization ID.
|
|
85
|
-
# @param [Integer] limit A pagination argument used to limit the number
|
|
86
|
-
# of listed Organizations that are returned.
|
|
87
|
-
sig do
|
|
88
|
-
params(
|
|
89
|
-
options: T::Hash[Symbol, String],
|
|
90
|
-
).returns(WorkOS::Types::ListStruct)
|
|
91
|
-
end
|
|
92
|
-
def list_organizations(options = {})
|
|
93
|
-
response = execute_request(
|
|
94
|
-
request: get_request(
|
|
95
|
-
path: '/organizations',
|
|
96
|
-
auth: true,
|
|
97
|
-
params: options,
|
|
98
|
-
),
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
parsed_response = JSON.parse(response.body)
|
|
102
|
-
|
|
103
|
-
organizations = parsed_response['data'].map do |organization|
|
|
104
|
-
::WorkOS::Organization.new(organization.to_json)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
WorkOS::Types::ListStruct.new(
|
|
108
|
-
data: organizations,
|
|
109
|
-
list_metadata: parsed_response['listMetadata'],
|
|
110
|
-
)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
52
|
private
|
|
114
53
|
|
|
115
|
-
sig { params(response: Net::HTTPResponse).void }
|
|
116
|
-
def check_and_raise_organization_error(response:)
|
|
117
|
-
begin
|
|
118
|
-
body = JSON.parse(response.body)
|
|
119
|
-
return unless body['message']
|
|
120
|
-
|
|
121
|
-
message = body['message']
|
|
122
|
-
request_id = response['x-request-id']
|
|
123
|
-
rescue StandardError
|
|
124
|
-
message = 'Something went wrong'
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
raise APIError.new(
|
|
128
|
-
message: message,
|
|
129
|
-
http_status: nil,
|
|
130
|
-
request_id: request_id,
|
|
131
|
-
)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
54
|
sig { params(intent: String).void }
|
|
135
55
|
def validate_intent(intent)
|
|
136
56
|
return if GENERATE_LINK_INTENTS.include?(intent)
|
data/lib/workos/profile.rb
CHANGED
|
@@ -13,7 +13,7 @@ module WorkOS
|
|
|
13
13
|
sig { returns(String) }
|
|
14
14
|
attr_accessor :id, :email, :first_name, :last_name, :connection_id,
|
|
15
15
|
:connection_type, :idp_id, :raw_attributes
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
sig { params(profile_json: String).void }
|
|
18
18
|
def initialize(profile_json)
|
|
19
19
|
raw = parse_json(profile_json)
|
|
@@ -27,7 +27,6 @@ module WorkOS
|
|
|
27
27
|
@idp_id = raw.idp_id
|
|
28
28
|
@raw_attributes = raw.raw_attributes
|
|
29
29
|
end
|
|
30
|
-
# rubocop:enable Metrics/AbcSize
|
|
31
30
|
|
|
32
31
|
sig { returns(String) }
|
|
33
32
|
def full_name
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
3
|
+
|
|
4
|
+
module WorkOS
|
|
5
|
+
# The ProfileAndToken class represents a Profile and a corresponding
|
|
6
|
+
# Access Token. This class is not meant to be instantiated in user space, and
|
|
7
|
+
# is instantiated internally but exposed.
|
|
8
|
+
class ProfileAndToken
|
|
9
|
+
extend T::Sig
|
|
10
|
+
|
|
11
|
+
attr_accessor :access_token, :profile
|
|
12
|
+
|
|
13
|
+
sig { params(profile_and_token_json: String).void }
|
|
14
|
+
def initialize(profile_and_token_json)
|
|
15
|
+
json = JSON.parse(profile_and_token_json, symbolize_names: true)
|
|
16
|
+
|
|
17
|
+
@access_token = T.let(json[:access_token], String)
|
|
18
|
+
@profile = WorkOS::Profile.new(profile_and_token_json)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_json(*)
|
|
22
|
+
{
|
|
23
|
+
access_token: access_token,
|
|
24
|
+
profile: profile.to_json,
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|