workos 0.11.1 → 1.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1368d9f2e05190d798f6b29b419ec7e4ad220074973f4fbd0e06096808854886
4
- data.tar.gz: eaa0cb1aef9de77897c949cbd7c4652c24163f33b3f87fd67920c41ebea691de
3
+ metadata.gz: 5088a3dd82cef707b21e05ece2df2966516576c48f7f389aacaffe4c5301f755
4
+ data.tar.gz: ac715b624752ff8266a3fa714c698b77b4b1d8b64d38aaff9505882549715082
5
5
  SHA512:
6
- metadata.gz: eb2a17a7450f9f54a91fdb1f2eeeb8ae63ee8d4fa9ffd4086d0e7f012e562130a6198dc7a8a9750b67312d7f678abb9a4a2e8f9af228df116386931cfcd92cba
7
- data.tar.gz: 40e578a8e57f22675db3911c636564b8eeb31bda2d07685a0349d57da02fb09f1aab14e22c702939e44e3315e6dc6b138943e571893a41c57931f32bec407718
6
+ metadata.gz: 6552a77d12715130a9f8f90f46359b33f79d9ee0d076fd2d8ee47c403b9156d4f32a115e850482d2ca19da0b6f95bb226459835f73ff3304f3b63e3c7105df8c
7
+ data.tar.gz: baefeeb217e2394450fadfa3305e93da63b4dc7266c49d872c9d9c1394c1399dc767696432c6136a4272d3a554ed6408a33c3eabb7083461df5081f7e5fc032a
data/.rubocop.yml CHANGED
@@ -20,3 +20,5 @@ Style/TrailingCommaInArguments:
20
20
  EnforcedStyleForMultiline: 'consistent_comma'
21
21
  Style/TrailingCommaInHashLiteral:
22
22
  EnforcedStyleForMultiline: 'consistent_comma'
23
+ AllCops:
24
+ TargetRubyVersion: 2.5
@@ -33,13 +33,13 @@ blocks:
33
33
  - name: Ruby 1.9.3
34
34
  commands:
35
35
  - checkout
36
- - sem-version ruby 1.9.3
36
+ - sem-version ruby 1.9.3-p551
37
37
  - bundle install
38
38
  - bundle exec rspec
39
39
  - name: Ruby 2.0.0
40
40
  commands:
41
41
  - checkout
42
- - sem-version ruby 2.0.0
42
+ - sem-version ruby 2.0.0-p648
43
43
  - bundle install
44
44
  - bundle exec rspec
45
45
  - name: Ruby 2.3.4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- workos (0.11.1)
4
+ workos (1.2.1)
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.6391)
63
+ sorbet-runtime (0.5.6427)
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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 WorkOS
3
+ Copyright (c) 2021 WorkOS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,22 +1,22 @@
1
- # workos-ruby [![codecov](https://codecov.io/gh/workos-inc/workos-ruby/branch/master/graph/badge.svg)](https://codecov.io/gh/workos-inc/workos-ruby)
1
+ # WorkOS Ruby Library
2
2
 
3
- WorkOS official Ruby gem for interacting with WorkOS APIs
3
+ The WorkOS library for Ruby provides convenient access to the WorkOS API from applications written in Ruby.
4
4
 
5
5
  ## Documentation
6
6
 
7
- Complete documentation for the latest version of WorkOS Ruby Gem can be found [here](https://workos-inc.github.io/workos-ruby/).
7
+ See the [API Reference](https://workos.com/docs/reference/client-libraries) for Ruby usage examples.
8
8
 
9
9
  ## Installation
10
10
 
11
- To get started, you can install the WorkOS gem via RubyGems with:
11
+ Install the package with:
12
12
 
13
- ```ruby
13
+ ```
14
14
  gem install workos
15
15
  ```
16
16
 
17
17
  If you're using Bundler to manage your application's gems, add the WorkOS gem to your Gemfile:
18
18
 
19
- ```ruby
19
+ ```
20
20
  source 'https://rubygems.org'
21
21
 
22
22
  gem 'workos'
@@ -24,17 +24,13 @@ gem 'workos'
24
24
 
25
25
  ## Configuration
26
26
 
27
- To use the SDK you must first provide your API key from the [WorkOS Developer Dashboard](https://dashboard.workos.com/api-keys).
28
-
29
- You can do this through the `WORKOS_API_KEY` environment variable or by calling `WorkOS.key = [your API key]`.
30
-
31
- The WorkOS Gem will read the environment variable `WORKOS_API_KEY`:
27
+ To use the library you must provide an API key, located in the WorkOS dashboard, as an environment variable `WORKOS_API_KEY`:
32
28
 
33
29
  ```sh
34
30
  $ WORKOS_API_KEY=[your api key] ruby app.rb
35
31
  ```
36
32
 
37
- Alternatively, you may set the key yourself, such as in an initializer in your application load path:
33
+ Or, you may set the key yourself, such as in an initializer in your application load path:
38
34
 
39
35
  ```ruby
40
36
  # /config/initializers/workos.rb
@@ -42,222 +38,9 @@ Alternatively, you may set the key yourself, such as in an initializer in your a
42
38
  WorkOS.key = '[your api key]'
43
39
  ```
44
40
 
45
- ## The SSO Module
46
-
47
- The SSO Module provides convenient methods for authenticating a Single Sign On (SSO) user via WorkOS. WorkOS SSO follows the OAuth 2.0 specification.
48
-
49
- First, you'll direct your SSO users to an `authorization_url`. They will sign in to their SSO account with their Identity Provider, and be redirected to a
50
- callback URL that you set in your WorkOS Dashboard. The user will be redirected with a `code` URL parameter, which you can then exchange for a WorkOS::Profile
51
- using the `WorkOS::SSO.get_profile` method.
52
-
53
- See our Ruby SSO example app for a [complete example](https://github.com/workos-inc/ruby-sso-example).
54
-
55
- ```ruby
56
- WorkOS::SSO.authorization_url(domain:, client_id:, redirect_uri:, state: {})
57
- ```
58
-
59
- > Generate an authorization URL to intitiate the WorkOS OAuth2 workflow.
60
-
61
- `WorkOS::SSO.authorization_url` accepts four arguments:
62
-
63
- - `domain` (string) — the authenticating user's company domain, without protocol (ex. `example.com`)
64
- - `client_id` (string) — your application's WorkOS [Client ID](https://dashboard.workos.com/sso/configuration) (ex. `project_01JG3BCPTRTSTTWQR4VSHXGWCQ`)
65
- - `state` (optional, hash) — an optional hash used to manage state across authorization transactions (ex. `{ next_page: '/docs'}`)
66
- - `redirect_uri` (string) — a callback URL where your application redirects the user-agent after an authorization code is granted (ex. `workos.dev/callback`). This must match one of your configured callback URLs for the associated environment on your WorkOS dashboard.
67
-
68
- This method will return an OAuth2 query string of the form:
69
-
70
- `https://${domain}/sso/authorize?response_type=code&client_id=${clientID}&redirect_uri=${redirectURI}&state=${state}`
71
-
72
- For example, when used in a [Sinatra app](http://sinatrarb.com/):
73
-
74
- ```ruby
75
- DOMAIN = 'example.com'
76
- CLIENT_ID = '{clientId}'
77
- REDIRECT_URI = 'http://localhost:4567/callback'
78
-
79
- get '/auth' do
80
- authorization_url = WorkOS::SSO.authorization_url(
81
- domain: DOMAIN,
82
- client_id: CLIENT_ID,
83
- redirect_uri: REDIRECT_URI,
84
- )
85
-
86
- redirect authorization_url
87
- end
88
- ```
89
-
90
- The user would be redirected to:
91
-
92
- `https://api.workos.com/sso/authorize?response_type=code&client_id={clientID}&redirect_uri=http://localhost:4567/callback`
93
-
94
- WorkOS takes over from here, sending the user to authenticate with their IDP, and on successful login, returns
95
- the user to your callback URL with a `code` parameter. You'll use `WorkOS::SSO.profile` to exchange the
96
- code for a `WorkOS::Profile`.
97
-
98
- ```ruby
99
- WorkOS::SSO.profile(code:, client_id:)
100
- ```
101
-
102
- > Fetch a WorkOS::Profile for an authorized user.
103
-
104
- `WorkOS::SSO.profile` accepts two arguments:
105
-
106
- - `code` (string) — an opaque string provided by the authorization server; will be exchanged for an Access Token when the user's profile is sent
107
- - `client_id` (string) — your application's WorkOS [Client ID](https://dashboard.workos.com/sso/configuration) (ex. `project_01JG3BCPTRTSTTWQR4VSHXGWCQ`)
108
-
109
- This method will return an instance of a `WorkOS::Profile` with the following attributes:
110
-
111
- ```ruby
112
- <WorkOS::Profile:0x00007fb6e4193d20
113
- @id="prof_01DRA1XNSJDZ19A31F183ECQW5",
114
- @email="demo@workos-okta.com",
115
- @first_name="WorkOS",
116
- @connection_id="conn_01EMH8WAK20T42N2NBMNBCYHAG",
117
- @connection_type="OktaSAML",
118
- @last_name="Demo",
119
- @idp_id="00u1klkowm8EGah2H357",
120
- @raw_attributes={
121
- :id=>"prof_01DRA1XNSJDZ19A31F183ECQW5",
122
- :email=>"demo@workos-okta.com",
123
- :first_name=>"WorkOS",
124
- :last_name=>"Demo",
125
- :idp_id=>"00u1klkowm8EGah2H357"
126
- },
127
- >
128
- ```
129
-
130
- Our Sinatra app can be extended to use this method:
131
-
132
- ```ruby
133
- DOMAIN = 'example.com'
134
- CLIENT_ID = '{clientId}'
135
- REDIRECT_URI = 'http://localhost:4567/callback'
136
-
137
- get '/auth' do
138
- authorization_url = WorkOS::SSO.authorization_url(
139
- domain: DOMAIN,
140
- client_id: CLIENT_ID,
141
- redirect_uri: REDIRECT_URI,
142
- )
143
-
144
- redirect authorization_url
145
- end
146
-
147
- get '/callback' do
148
- profile = WorkOS::SSO.profile(
149
- code: params['code'],
150
- client_id: CLIENT_ID,
151
- )
152
-
153
- session[:user] = profile.to_json
154
-
155
- redirect '/'
156
- end
157
- ```
158
-
159
- Given the `WorkOS::Profile`, you can now sign the user in according to your own authentication setup.
160
-
161
- ## The Magic Link Module
162
-
163
- The Magic Link Module provides methods for authenticating a Passwordless user via WorkOS.
164
-
165
- First, you'll create a Passwordless Session for a Magic Link connection.
166
- Then, using the session ID, you'll email a user the Magic Link confirmation URL.
167
- The user can then click on that link to be authenticated to your application.
168
-
169
- > Create a Passwordless Session for a Magic Link Connection.
170
-
171
- `WorkOS::Passwordless.create_session` accepts four arguments:
172
-
173
- - `email` (string) - the email of the user to authenticate.
174
- - `type` (string) - The type of Passwordless Session to create. Currently, the only supported value is `MagicLink`.
175
- - `state` (optional, string) - Optional parameter that a Developer can choose to include in their authorization URL. If included, then the redirect URI received from WorkOS will contain the exact `state` that was passed in the authorization URL.
176
- - `redirect_uri` (string) - a callback URL where your application redirects the user-agent after an authorization code is granted (ex. `workos.dev/callback`). This must match one of your configured callback URLs for the associated environment on your WorkOS dashboard.
177
-
178
- This method will return a Passwordless Session object, containing the following attributes:
179
-
180
- - `id` (string) - the unique ID of the session.
181
- - `email` (string) - the email address of the user for the session.
182
- - `expires_at` (date) - the ISO-8601 datetime at which the session expires.
183
- - `link` (string) - the link for the user to authenticate with. You can use this link to send a custom email to the user, or send an email using the `WorkOS::Passwordless.send_session` method, described below.
184
-
185
- > Email a user the Magic Link confirmation URL.
186
-
187
- `WorkOS::Passwordless.send_session` accepts one argument:
188
-
189
- - `id` (string) - the unique identifier of the Passwordless Session to send an email for.
190
-
191
- This method will return a boolean confirming the Magic Link was sent.
192
-
193
- > Example with Sinatra application
194
-
195
- Our Sinatra app can be altered to use Magic Link:
196
-
197
- ```ruby
198
- CLIENT_ID = '{clientId}'
199
- REDIRECT_URI = 'http://localhost:4567/callback'
200
-
201
- post '/passwordless-auth' do
202
- session = WorkOS::Passwordless.create_session(
203
- email: params[:email],
204
- type: 'MagicLink',
205
- redirect_uri: REDIRECT_URI
206
- )
207
- WorkOS::Passwordless.send_session(session.id)
208
-
209
- redirect '/check-email'
210
- end
211
-
212
- get '/callback' do
213
- profile = WorkOS::SSO.profile(
214
- code: params['code'],
215
- client_id: CLIENT_ID,
216
- )
217
-
218
- session[:user] = profile.to_json
219
-
220
- redirect '/'
221
- end
222
- ```
223
-
224
- ## The Audit Trail Module
225
-
226
- The Audit Trail Module provides methods for creating Audit Trail events on
227
- WorkOS.
228
-
229
- See our [Audit Trail
230
- Overview](https://docs.workos.com/audit-trail/overview) for
231
- more information.
232
-
233
- ```ruby
234
- payload = {
235
- group: 'Foo Corp',
236
- location: '127.0.0.1',
237
- action: 'user.created',
238
- action_type: 'C',
239
- actor_name: 'Foo',
240
- actor_id: 'user_12345',
241
- target_name: 'Bar',
242
- target_id: 'user_67890',
243
- occurred_at: '2020-01-10T15:30:00-05:00',
244
- metadata: {
245
- source: 'Email',
246
- }
247
- }
248
-
249
- WorkOS::AuditTrail.create_event(event: payload)
250
- ```
251
-
252
- ### Idempotency
253
-
254
- To perform an idempotent request, provide an additional idempotency_key
255
- parameter to the `create_event` options.
256
-
257
- ```ruby
258
- WorkOS::AuditTrail.create_event(event: payload, idempotency_key: 'key123456')
259
- ```
41
+ ## More Information
260
42
 
261
- See our [API
262
- Reference](https://docs.workos.com/audit-trail/api-reference#idempotency)
263
- for more information on idempotency keys.
43
+ * [Single Sign-On Guide](https://workos.com/docs/sso/guide)
44
+ * [Directory Sync Guide](https://workos.com/docs/directory-sync/guide)
45
+ * [Admin Portal Guide](https://workos.com/docs/admin-portal/guide)
46
+ * [Magic Link Guide](https://workos.com/docs/magic-link/guide)
data/lib/workos.rb CHANGED
@@ -35,9 +35,11 @@ module WorkOS
35
35
  autoload :Directory, 'workos/directory'
36
36
  autoload :DirectoryGroup, 'workos/directory_group'
37
37
  autoload :Organization, 'workos/organization'
38
+ autoload :Organizations, 'workos/organizations'
38
39
  autoload :Passwordless, 'workos/passwordless'
39
40
  autoload :Portal, 'workos/portal'
40
41
  autoload :Profile, 'workos/profile'
42
+ autoload :ProfileAndToken, 'workos/profile_and_token'
41
43
  autoload :SSO, 'workos/sso'
42
44
  autoload :DirectoryUser, 'workos/directory_user'
43
45
 
data/lib/workos/client.rb CHANGED
@@ -19,7 +19,7 @@ module WorkOS
19
19
 
20
20
  sig do
21
21
  params(
22
- request: T.any(Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Delete),
22
+ request: T.any(Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Delete, Net::HTTP::Put),
23
23
  ).returns(::T.untyped)
24
24
  end
25
25
  def execute_request(request:)
@@ -36,9 +36,10 @@ module WorkOS
36
36
  path: String,
37
37
  auth: T.nilable(T::Boolean),
38
38
  params: T.nilable(Hash),
39
+ access_token: T.nilable(String),
39
40
  ).returns(Net::HTTP::Get)
40
41
  end
41
- def get_request(path:, auth: false, params: {})
42
+ def get_request(path:, auth: false, params: {}, access_token: nil)
42
43
  uri = URI(path)
43
44
  uri.query = URI.encode_www_form(params) if params
44
45
 
@@ -47,7 +48,7 @@ module WorkOS
47
48
  'Content-Type' => 'application/json',
48
49
  )
49
50
 
50
- request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
51
+ request['Authorization'] = "Bearer #{access_token || WorkOS.key!}" if auth
51
52
  request['User-Agent'] = user_agent
52
53
  request
53
54
  end
@@ -90,6 +91,23 @@ module WorkOS
90
91
  request
91
92
  end
92
93
 
94
+ sig do
95
+ params(
96
+ path: String,
97
+ auth: T.nilable(T::Boolean),
98
+ idempotency_key: T.nilable(String),
99
+ body: T.nilable(Hash),
100
+ ).returns(Net::HTTP::Put)
101
+ end
102
+ def put_request(path:, auth: false, idempotency_key: nil, body: nil)
103
+ request = Net::HTTP::Put.new(path, 'Content-Type' => 'application/json')
104
+ request.body = body.to_json if body
105
+ request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
106
+ request['Idempotency-Key'] = idempotency_key if idempotency_key
107
+ request['User-Agent'] = user_agent
108
+ request
109
+ end
110
+
93
111
  sig { returns(String) }
94
112
  def user_agent
95
113
  engine = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'Ruby'
@@ -5,11 +5,12 @@ module WorkOS
5
5
  # The Connection class provides a lightweight wrapper around
6
6
  # a WorkOS Connection resource. This class is not meant to be instantiated
7
7
  # in user space, and is instantiated internally but exposed.
8
+ # Note: status is deprecated - use state instead
8
9
  class Connection
9
10
  extend T::Sig
10
11
 
11
12
  attr_accessor :id, :name, :connection_type, :domains, :organization_id,
12
- :status
13
+ :state, :status
13
14
 
14
15
  sig { params(json: String).void }
15
16
  def initialize(json)
@@ -20,6 +21,7 @@ module WorkOS
20
21
  @connection_type = T.let(raw.connection_type, String)
21
22
  @domains = T.let(raw.domains, Array)
22
23
  @organization_id = T.let(raw.organization_id, String)
24
+ @state = T.let(raw.state, String)
23
25
  @status = T.let(raw.status, String)
24
26
  end
25
27
 
@@ -30,6 +32,7 @@ module WorkOS
30
32
  connection_type: connection_type,
31
33
  domains: domains,
32
34
  organization_id: organization_id,
35
+ state: state,
33
36
  status: status,
34
37
  }
35
38
  end
@@ -46,6 +49,7 @@ module WorkOS
46
49
  connection_type: hash[:connection_type],
47
50
  domains: hash[:domains],
48
51
  organization_id: hash[:organization_id],
52
+ state: hash[:state],
49
53
  status: hash[:status],
50
54
  )
51
55
  end
@@ -0,0 +1,171 @@
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::Organization]
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
+ # Delete an Organization
129
+ #
130
+ # @param [String] id Organization unique identifier
131
+ #
132
+ # @example
133
+ # WorkOS::SSO.delete_organization(id: 'org_01EHZNVPK3SFK441A1RGBFSHRT')
134
+ # => true
135
+ #
136
+ # @return [Bool] - returns `true` if successful
137
+ sig { params(id: String).returns(T::Boolean) }
138
+ def delete_organization(id:)
139
+ request = delete_request(
140
+ auth: true,
141
+ path: "/organizations/#{id}",
142
+ )
143
+
144
+ response = execute_request(request: request)
145
+
146
+ response.is_a? Net::HTTPSuccess
147
+ end
148
+
149
+ private
150
+
151
+ sig { params(response: Net::HTTPResponse).void }
152
+ def check_and_raise_organization_error(response:)
153
+ begin
154
+ body = JSON.parse(response.body)
155
+ return unless body['message']
156
+
157
+ message = body['message']
158
+ request_id = response['x-request-id']
159
+ rescue StandardError
160
+ message = 'Something went wrong'
161
+ end
162
+
163
+ raise APIError.new(
164
+ message: message,
165
+ http_status: nil,
166
+ request_id: request_id,
167
+ )
168
+ end
169
+ end
170
+ end
171
+ end