workos 0.8.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +5 -0
  3. data/.rubocop.yml +4 -0
  4. data/Gemfile.lock +2 -4
  5. data/README.md +119 -55
  6. data/docs/WorkOS/SSO.html +235 -235
  7. data/docs/file.README.html +20 -20
  8. data/lib/workos.rb +1 -0
  9. data/lib/workos/audit_trail.rb +1 -0
  10. data/lib/workos/client.rb +22 -1
  11. data/lib/workos/connection.rb +0 -2
  12. data/lib/workos/organization.rb +0 -2
  13. data/lib/workos/passwordless.rb +3 -2
  14. data/lib/workos/portal.rb +0 -6
  15. data/lib/workos/profile.rb +6 -4
  16. data/lib/workos/sso.rb +119 -13
  17. data/lib/workos/types.rb +8 -3
  18. data/lib/workos/types/profile_struct.rb +1 -0
  19. data/lib/workos/version.rb +1 -1
  20. data/spec/lib/workos/passwordless_spec.rb +1 -0
  21. data/spec/lib/workos/sso_spec.rb +199 -7
  22. data/spec/support/fixtures/vcr_cassettes/audit_trail/get_events.yml +2 -2
  23. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories.yml +1 -1
  24. data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories_with_domain_param.yml +1 -1
  25. data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_invalid_id.yml +72 -0
  26. data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_valid_id.yml +70 -0
  27. data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_invalid_id.yml +72 -0
  28. data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +74 -0
  29. data/spec/support/fixtures/vcr_cassettes/sso/list_connections.yml +72 -0
  30. data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_after_param.yml +72 -0
  31. data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_before_param.yml +73 -0
  32. data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_connection_type_param.yml +72 -0
  33. data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_domain_param.yml +72 -0
  34. data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_limit_param.yml +72 -0
  35. data/spec/support/profile.txt +1 -1
  36. data/workos.gemspec +0 -1
  37. metadata +24 -18
  38. data/CODEOWNERS +0 -1
@@ -5,9 +5,9 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>
7
7
  File: README
8
-
8
+
9
9
  &mdash; Documentation by YARD 0.9.22
10
-
10
+
11
11
  </title>
12
12
 
13
13
  <link rel="stylesheet" href="css/style.css" type="text/css" />
@@ -35,14 +35,14 @@
35
35
  <div id="main" tabindex="-1">
36
36
  <div id="header">
37
37
  <div id="menu">
38
-
39
- <a href="_index.html">Index</a> &raquo;
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
40
  <span class="title">File: README</span>
41
-
41
+
42
42
  </div>
43
43
 
44
44
  <div id="search">
45
-
45
+
46
46
  <a class="full_list_link" id="class_list_link"
47
47
  href="class_list.html">
48
48
 
@@ -52,7 +52,7 @@
52
52
  <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
53
53
  </svg>
54
54
  </a>
55
-
55
+
56
56
  </div>
57
57
  <div class="clear"></div>
58
58
  </div>
@@ -139,7 +139,7 @@
139
139
 
140
140
  <p>See our Ruby SSO example app for a <a href="https://github.com/workos-inc/ruby-sso-example">complete example</a>.</p>
141
141
 
142
- <pre class="code ruby"><code class="ruby">WorkOS::SSO.authorization_url(domain:, project_id:, redirect_uri:, state: {})
142
+ <pre class="code ruby"><code class="ruby">WorkOS::SSO.authorization_url(domain:, client_id:, redirect_uri:, state: {})
143
143
  </code></pre>
144
144
 
145
145
  <blockquote>
@@ -150,27 +150,27 @@
150
150
  <ul><li>
151
151
  <p><code>domain</code> (string) — the authenticating user&#39;s company domain, without protocol (ex. <code>example.com</code>)</p>
152
152
  </li><li>
153
- <p><code>project_id</code> (string) — your application&#39;s WorkOS <a href="https://dashboard.workos.com/sso/configuration">Project ID</a> (ex. <code>project_01JG3BCPTRTSTTWQR4VSHXGWCQ</code>)</p>
153
+ <p><code>client_id</code> (string) — your application&#39;s WorkOS <a href="https://dashboard.workos.com/sso/configuration">Client ID</a> (ex. <code>project_01JG3BCPTRTSTTWQR4VSHXGWCQ</code>)</p>
154
154
  </li><li>
155
155
  <p><code>state</code> (optional, hash) — an optional hash used to manage state across authorization transactions (ex. <code>{ next_page: &#39;/docs&#39;}</code>)</p>
156
156
  </li><li>
157
- <p><code>redirect_uri</code> (string) — a callback URL where your application redirects the user-agent after an authorization code is granted (ex. <code>workos.dev/callback</code>). This must match one of your configured callback URLs for the associated project on your WorkOS dashboard.</p>
157
+ <p><code>redirect_uri</code> (string) — a callback URL where your application redirects the user-agent after an authorization code is granted (ex. <code>workos.dev/callback</code>). This must match one of your configured callback URLs for the associated environment on your WorkOS dashboard.</p>
158
158
  </li></ul>
159
159
 
160
160
  <p>This method will return an OAuth2 query string of the form:</p>
161
161
 
162
- <p><code>https://${domain}/sso/authorize?response_type=code&client_id=${projectID}&redirect_uri=${redirectURI}&state=${state}</code></p>
162
+ <p><code>https://${domain}/sso/authorize?response_type=code&client_id=${clientID}&redirect_uri=${redirectURI}&state=${state}</code></p>
163
163
 
164
164
  <p>For example, when used in a <a href="http://sinatrarb.com/">Sinatra app</a>:</p>
165
165
 
166
166
  <pre class="code ruby"><code class="ruby"><span class='const'>DOMAIN</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>example.com</span><span class='tstring_end'>&#39;</span></span>
167
- <span class='const'>PROJECT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>{projectId}</span><span class='tstring_end'>&#39;</span></span>
167
+ <span class='const'>CLIENT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>{clientId}</span><span class='tstring_end'>&#39;</span></span>
168
168
  <span class='const'>REDIRECT_URI</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>http://localhost:4567/callback</span><span class='tstring_end'>&#39;</span></span>
169
169
 
170
170
  <span class='id identifier rubyid_get'>get</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>/auth</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
171
171
  <span class='id identifier rubyid_authorization_url'>authorization_url</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="WorkOS.html" title="WorkOS (module)">WorkOS</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="WorkOS/SSO.html" title="WorkOS::SSO (module)">SSO</a></span></span><span class='period'>.</span><span class='id identifier rubyid_authorization_url'><span class='object_link'><a href="WorkOS/SSO.html#authorization_url-class_method" title="WorkOS::SSO.authorization_url (method)">authorization_url</a></span></span><span class='lparen'>(</span>
172
172
  <span class='label'>domain:</span> <span class='const'>DOMAIN</span><span class='comma'>,</span>
173
- <span class='label'>project_id:</span> <span class='const'>PROJECT_ID</span><span class='comma'>,</span>
173
+ <span class='label'>client_id:</span> <span class='const'>CLIENT_ID</span><span class='comma'>,</span>
174
174
  <span class='label'>redirect_uri:</span> <span class='const'>REDIRECT_URI</span><span class='comma'>,</span>
175
175
  <span class='rparen'>)</span>
176
176
 
@@ -180,11 +180,11 @@
180
180
 
181
181
  <p>The user would be redirected to:</p>
182
182
 
183
- <p><code>https://api.workos.com/sso/authorize?response_type=code&client_id={projectID}&redirect_uri=http://localhost:4567/callback</code></p>
183
+ <p><code>https://api.workos.com/sso/authorize?response_type=code&client_id={clientID}&redirect_uri=http://localhost:4567/callback</code></p>
184
184
 
185
185
  <p>WorkOS takes over from here, sending the user to authenticate with their IDP, and on successful login, returns the user to your callback URL with a <code>code</code> parameter. You&#39;ll use <code>WorkOS::SSO.profile</code> to exchange the code for a <code>WorkOS::Profile</code>.</p>
186
186
 
187
- <pre class="code ruby"><code class="ruby">WorkOS::SSO.profile(code:, project_id:)&lt;/h4&gt;
187
+ <pre class="code ruby"><code class="ruby">WorkOS::SSO.profile(code:, client_id:)&lt;/h4&gt;
188
188
  </code></pre>
189
189
 
190
190
  <blockquote>
@@ -195,7 +195,7 @@
195
195
  <ul><li>
196
196
  <p><code>code</code> (string) — an opaque string provided by the authorization server; will be exchanged for an Access Token when the user&#39;s profile is sent</p>
197
197
  </li><li>
198
- <p><code>project_id</code> (string) — your application&#39;s WorkOS <a href="https://dashboard.workos.com/sso/configuration">Project ID</a> (ex. <code>project_01JG3BCPTRTSTTWQR4VSHXGWCQ</code>)</p>
198
+ <p><code>client_id</code> (string) — your application&#39;s WorkOS <a href="https://dashboard.workos.com/sso/configuration">Client ID</a> (ex. <code>project_01JG3BCPTRTSTTWQR4VSHXGWCQ</code>)</p>
199
199
  </li></ul>
200
200
 
201
201
  <p>This method will return an instance of a <code>WorkOS::Profile</code> with the following attributes:</p>
@@ -213,13 +213,13 @@
213
213
  <p>Our Sintatra app can be extended to use this method:</p>
214
214
 
215
215
  <pre class="code ruby"><code class="ruby"><span class='const'>DOMAIN</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>example.com</span><span class='tstring_end'>&#39;</span></span>
216
- <span class='const'>PROJECT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>{projectId}</span><span class='tstring_end'>&#39;</span></span>
216
+ <span class='const'>CLIENT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>{clientId}</span><span class='tstring_end'>&#39;</span></span>
217
217
  <span class='const'>REDIRECT_URI</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>http://localhost:4567/callback</span><span class='tstring_end'>&#39;</span></span>
218
218
 
219
219
  <span class='id identifier rubyid_get'>get</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>/auth</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
220
220
  <span class='id identifier rubyid_authorization_url'>authorization_url</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="WorkOS.html" title="WorkOS (module)">WorkOS</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="WorkOS/SSO.html" title="WorkOS::SSO (module)">SSO</a></span></span><span class='period'>.</span><span class='id identifier rubyid_authorization_url'><span class='object_link'><a href="WorkOS/SSO.html#authorization_url-class_method" title="WorkOS::SSO.authorization_url (method)">authorization_url</a></span></span><span class='lparen'>(</span>
221
221
  <span class='label'>domain:</span> <span class='const'>DOMAIN</span><span class='comma'>,</span>
222
- <span class='label'>project_id:</span> <span class='const'>PROJECT_ID</span><span class='comma'>,</span>
222
+ <span class='label'>client_id:</span> <span class='const'>CLIENT_ID</span><span class='comma'>,</span>
223
223
  <span class='label'>redirect_uri:</span> <span class='const'>REDIRECT_URI</span><span class='comma'>,</span>
224
224
  <span class='rparen'>)</span>
225
225
 
@@ -229,7 +229,7 @@
229
229
  <span class='id identifier rubyid_get'>get</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>/callback</span><span class='tstring_end'>&#39;</span></span> <span class='kw'>do</span>
230
230
  <span class='id identifier rubyid_profile'>profile</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="WorkOS.html" title="WorkOS (module)">WorkOS</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="WorkOS/SSO.html" title="WorkOS::SSO (module)">SSO</a></span></span><span class='period'>.</span><span class='id identifier rubyid_profile'><span class='object_link'><a href="WorkOS/SSO.html#profile-class_method" title="WorkOS::SSO.profile (method)">profile</a></span></span><span class='lparen'>(</span>
231
231
  <span class='label'>code:</span> <span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>code</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='comma'>,</span>
232
- <span class='label'>project_id:</span> <span class='const'>PROJECT_ID</span><span class='comma'>,</span>
232
+ <span class='label'>client_id:</span> <span class='const'>CLIENT_ID</span><span class='comma'>,</span>
233
233
  <span class='rparen'>)</span>
234
234
 
235
235
  <span class='id identifier rubyid_session'>session</span><span class='lbracket'>[</span><span class='symbol'>:user</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_profile'>profile</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span>
@@ -249,4 +249,4 @@
249
249
 
250
250
  </div>
251
251
  </body>
252
- </html>
252
+ </html>
data/lib/workos.rb CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'workos/version'
5
5
  require 'sorbet-runtime'
6
+ require 'json'
6
7
 
7
8
  # Use the WorkOS module to authenticate your
8
9
  # requests to the WorkOS API. The gem will read
@@ -51,6 +51,7 @@ module WorkOS
51
51
  def create_event(event:, idempotency_key: nil)
52
52
  request = post_request(
53
53
  path: '/events',
54
+ auth: true,
54
55
  idempotency_key: idempotency_key,
55
56
  body: event,
56
57
  )
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),
22
+ request: T.any(Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Delete),
23
23
  ).returns(::T.untyped)
24
24
  end
25
25
  def execute_request(request:)
@@ -69,6 +69,27 @@ module WorkOS
69
69
  request
70
70
  end
71
71
 
72
+ sig do
73
+ params(
74
+ path: String,
75
+ auth: T.nilable(T::Boolean),
76
+ params: T.nilable(Hash),
77
+ ).returns(Net::HTTP::Delete)
78
+ end
79
+ def delete_request(path:, auth: false, params: {})
80
+ uri = URI(path)
81
+ uri.query = URI.encode_www_form(params) if params
82
+
83
+ request = Net::HTTP::Delete.new(
84
+ uri.to_s,
85
+ 'Content-Type' => 'application/json',
86
+ )
87
+
88
+ request['Authorization'] = "Bearer #{WorkOS.key!}" if auth
89
+ request['User-Agent'] = user_agent
90
+ request
91
+ end
92
+
72
93
  sig { returns(String) }
73
94
  def user_agent
74
95
  engine = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : 'Ruby'
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: true
3
3
 
4
- require 'json'
5
-
6
4
  module WorkOS
7
5
  # The Connection class provides a lightweight wrapper around
8
6
  # a WorkOS Connection resource. This class is not meant to be instantiated
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: true
3
3
 
4
- require 'json'
5
-
6
4
  module WorkOS
7
5
  # The Organization class provides a lightweight wrapper around
8
6
  # a WorkOS Organization resource. This class is not meant to be instantiated
@@ -25,6 +25,9 @@ module WorkOS
25
25
  # redirects.
26
26
  # @option options [String] type The type of Passwordless Session to
27
27
  # create. Currently, the only supported value is 'MagicLink'.
28
+ # @option options [String] redirect_uri The URI where users are directed
29
+ # after completing the authentication step. Must match a
30
+ # configured redirect URI on your WorkOS dashboard.
28
31
  #
29
32
  # @return Hash
30
33
  sig do
@@ -33,7 +36,6 @@ module WorkOS
33
36
  ).returns(WorkOS::Types::PasswordlessSessionStruct)
34
37
  end
35
38
 
36
- # rubocop:disable Metrics/MethodLength
37
39
  def create_session(options)
38
40
  response = execute_request(
39
41
  request: post_request(
@@ -52,7 +54,6 @@ module WorkOS
52
54
  link: hash['link'],
53
55
  )
54
56
  end
55
- # rubocop:enable Metrics/MethodLength
56
57
 
57
58
  # Send a Passwordless Session via email.
58
59
  #
data/lib/workos/portal.rb CHANGED
@@ -55,7 +55,6 @@ module WorkOS
55
55
  return_url: T.nilable(String),
56
56
  ).returns(String)
57
57
  end
58
- # rubocop:disable Metrics/MethodLength
59
58
  def generate_link(intent:, organization:, return_url: nil)
60
59
  validate_intent(intent)
61
60
 
@@ -73,7 +72,6 @@ module WorkOS
73
72
 
74
73
  JSON.parse(response.body)['link']
75
74
  end
76
- # rubocop:enable Metrics/MethodLength
77
75
 
78
76
  # Retrieve a list of organizations that have connections configured
79
77
  # within your WorkOS dashboard.
@@ -91,7 +89,6 @@ module WorkOS
91
89
  options: T::Hash[Symbol, String],
92
90
  ).returns(WorkOS::Types::ListStruct)
93
91
  end
94
- # rubocop:disable Metrics/MethodLength
95
92
  def list_organizations(options = {})
96
93
  response = execute_request(
97
94
  request: get_request(
@@ -112,12 +109,10 @@ module WorkOS
112
109
  list_metadata: parsed_response['listMetadata'],
113
110
  )
114
111
  end
115
- # rubocop:enable Metrics/MethodLength
116
112
 
117
113
  private
118
114
 
119
115
  sig { params(response: Net::HTTPResponse).void }
120
- # rubocop:disable Metrics/MethodLength
121
116
  def check_and_raise_organization_error(response:)
122
117
  begin
123
118
  body = JSON.parse(response.body)
@@ -135,7 +130,6 @@ module WorkOS
135
130
  request_id: request_id,
136
131
  )
137
132
  end
138
- # rubocop:enable Metrics/MethodLength
139
133
 
140
134
  sig { params(intent: String).void }
141
135
  def validate_intent(intent)
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # typed: true
3
3
 
4
- require 'json'
5
-
6
4
  module WorkOS
7
5
  # The Profile class provides a lighweight wrapper around
8
6
  # a normalized response from the various IDPs WorkOS
@@ -13,9 +11,9 @@ module WorkOS
13
11
  extend T::Sig
14
12
 
15
13
  sig { returns(String) }
16
- attr_accessor :id, :email, :first_name, :last_name,
14
+ attr_accessor :id, :email, :first_name, :last_name, :connection_id,
17
15
  :connection_type, :idp_id, :raw_attributes
18
-
16
+ # rubocop:disable Metrics/AbcSize
19
17
  sig { params(profile_json: String).void }
20
18
  def initialize(profile_json)
21
19
  raw = parse_json(profile_json)
@@ -24,10 +22,12 @@ module WorkOS
24
22
  @email = T.let(raw.email, String)
25
23
  @first_name = raw.first_name
26
24
  @last_name = raw.last_name
25
+ @connection_id = T.let(raw.connection_id, String)
27
26
  @connection_type = T.let(raw.connection_type, String)
28
27
  @idp_id = raw.idp_id
29
28
  @raw_attributes = raw.raw_attributes
30
29
  end
30
+ # rubocop:enable Metrics/AbcSize
31
31
 
32
32
  sig { returns(String) }
33
33
  def full_name
@@ -40,6 +40,7 @@ module WorkOS
40
40
  email: email,
41
41
  first_name: first_name,
42
42
  last_name: last_name,
43
+ connection_id: connection_id,
43
44
  connection_type: connection_type,
44
45
  idp_id: idp_id,
45
46
  raw_attributes: raw_attributes,
@@ -58,6 +59,7 @@ module WorkOS
58
59
  email: hash[:profile][:email],
59
60
  first_name: hash[:profile][:first_name],
60
61
  last_name: hash[:profile][:last_name],
62
+ connection_id: hash[:profile][:connection_id],
61
63
  connection_type: hash[:profile][:connection_type],
62
64
  idp_id: hash[:profile][:idp_id],
63
65
  raw_attributes: hash[:profile][:raw_attributes],
data/lib/workos/sso.rb CHANGED
@@ -6,7 +6,7 @@ require 'uri'
6
6
 
7
7
  module WorkOS
8
8
  # The SSO module provides convenience methods for working with the WorkOS
9
- # SSO platform. You'll need a valid API key, a project ID, and to have
9
+ # SSO platform. You'll need a valid API key, a client ID, and to have
10
10
  # created an SSO connection on your WorkOS dashboard.
11
11
  #
12
12
  # @see https://docs.workos.com/sso/overview
@@ -26,8 +26,10 @@ module WorkOS
26
26
  # required
27
27
  # @param [String] provider A provider name for an Identity Provider
28
28
  # configured on your WorkOS dashboard. Only 'Google' is supported.
29
- # @param [String] project_id The WorkOS project ID for the project
29
+ # @param [String] client_id The WorkOS client ID for the environment
30
30
  # where you've configured your SSO connection.
31
+ # @param [String] project_id The WorkOS project ID for the project.
32
+ # The project_id is deprecated in Dashboard2.
31
33
  # @param [String] redirect_uri The URI where users are directed
32
34
  # after completing the authentication step. Must match a
33
35
  # configured redirect URI on your WorkOS dashboard.
@@ -36,7 +38,7 @@ module WorkOS
36
38
  # @example
37
39
  # WorkOS::SSO.authorization_url(
38
40
  # domain: 'acme.com',
39
- # project_id: 'project_01DG5TGK363GRVXP3ZS40WNGEZ',
41
+ # client_id: 'project_01DG5TGK363GRVXP3ZS40WNGEZ',
40
42
  # redirect_uri: 'https://workos.com/callback',
41
43
  # state: {
42
44
  # next_page: '/docs'
@@ -51,20 +53,32 @@ module WorkOS
51
53
  # @return [String]
52
54
  sig do
53
55
  params(
54
- project_id: String,
55
56
  redirect_uri: String,
57
+ project_id: T.nilable(String),
58
+ client_id: T.nilable(String),
56
59
  domain: T.nilable(String),
57
60
  provider: T.nilable(String),
58
61
  state: T.nilable(String),
59
62
  ).returns(String)
60
63
  end
61
64
  def authorization_url(
62
- project_id:, redirect_uri:, domain: nil, provider: nil, state: ''
65
+ redirect_uri:,
66
+ project_id: nil,
67
+ client_id: nil,
68
+ domain: nil,
69
+ provider: nil,
70
+ state: ''
63
71
  )
72
+ if project_id
73
+ warn '[DEPRECATION] `project_id` is deprecated.
74
+ Please use `client_id` instead.'
75
+ client_id = project_id
76
+ end
77
+
64
78
  validate_domain_and_provider(provider: provider, domain: domain)
65
79
 
66
80
  query = URI.encode_www_form({
67
- client_id: project_id,
81
+ client_id: client_id,
68
82
  redirect_uri: redirect_uri,
69
83
  response_type: 'code',
70
84
  state: state,
@@ -78,13 +92,15 @@ module WorkOS
78
92
  # Fetch the profile details for the authenticated SSO user.
79
93
  #
80
94
  # @param [String] code The authorization code provided in the callback URL
81
- # @param [String] project_id The WorkOS project ID for the project
95
+ # @param [String] client_id The WorkOS client ID for the environment
82
96
  # where you've configured your SSO connection
97
+ # @param [String] project_id The WorkOS project ID for the project.
98
+ # The project_id is deprecated in Dashboard2.
83
99
  #
84
100
  # @example
85
101
  # WorkOS::SSO.profile(
86
102
  # code: 'acme.com',
87
- # project_id: 'project_01DG5TGK363GRVXP3ZS40WNGEZ'
103
+ # client_id: 'project_01DG5TGK363GRVXP3ZS40WNGEZ'
88
104
  # )
89
105
  # => #<WorkOS::Profile:0x00007fb6e4193d20
90
106
  # @id="prof_01DRA1XNSJDZ19A31F183ECQW5",
@@ -97,10 +113,22 @@ module WorkOS
97
113
  # >
98
114
  #
99
115
  # @return [WorkOS::Profile]
100
- sig { params(code: String, project_id: String).returns(WorkOS::Profile) }
101
- def profile(code:, project_id:)
116
+ sig do
117
+ params(
118
+ code: String,
119
+ project_id: T.nilable(String),
120
+ client_id: T.nilable(String),
121
+ ).returns(WorkOS::Profile)
122
+ end
123
+ def profile(code:, project_id: nil, client_id: nil)
124
+ if project_id
125
+ warn '[DEPRECATION] `project_id` is deprecated.
126
+ Please use `client_id` instead.'
127
+ client_id = project_id
128
+ end
129
+
102
130
  body = {
103
- client_id: project_id,
131
+ client_id: client_id,
104
132
  client_secret: WorkOS.key!,
105
133
  grant_type: 'authorization_code',
106
134
  code: code,
@@ -168,6 +196,86 @@ module WorkOS
168
196
  WorkOS::Connection.new(response.body)
169
197
  end
170
198
 
199
+ # Retrieve connections.
200
+ #
201
+ # @param [Hash] options An options hash
202
+ # @option options [String] connection_type Authentication service
203
+ # provider descriptor.
204
+ # @option options [String] domain The domain of the connection to be
205
+ # retrieved.
206
+ # @option options [String] limit Maximum number of records to return.
207
+ # @option options [String] before Pagination cursor to receive records
208
+ # before a provided Connection ID.
209
+ # @option options [String] after Pagination cursor to receive records
210
+ # before a provided Connection ID.
211
+ #
212
+ # @return [Hash]
213
+ sig do
214
+ params(
215
+ options: T::Hash[Symbol, String],
216
+ ).returns(T::Array[T::Hash[String, T.nilable(String)]])
217
+ end
218
+ def list_connections(options = {})
219
+ response = execute_request(
220
+ request: get_request(
221
+ path: '/connections',
222
+ auth: true,
223
+ params: options,
224
+ ),
225
+ )
226
+
227
+ JSON.parse(response.body)['data']
228
+ end
229
+
230
+ # Get a Connection
231
+ #
232
+ # @param [String] id Connection unique identifier
233
+ #
234
+ # @example
235
+ # WorkOS::SSO.get_connection(id: 'conn_02DRA1XNSJDZ19A31F183ECQW9')
236
+ # => #<WorkOS::Connection:0x00007fb6e4193d20
237
+ # @id="conn_02DRA1XNSJDZ19A31F183ECQW9",
238
+ # @name="Foo Corp",
239
+ # @connection_type="OktaSAML",
240
+ # @domains=
241
+ # [{:object=>"connection_domain",
242
+ # :id=>"domain_01E6PK9N3XMD8RHWF7S66380AR",
243
+ # :domain=>"example.com"}]>
244
+ #
245
+ # @return [WorkOS::Connection]
246
+ sig { params(id: String).returns(WorkOS::Connection) }
247
+ def get_connection(id:)
248
+ request = get_request(
249
+ auth: true,
250
+ path: "/connections/#{id}",
251
+ )
252
+
253
+ response = execute_request(request: request)
254
+
255
+ WorkOS::Connection.new(response.body)
256
+ end
257
+
258
+ # Delete a Connection
259
+ #
260
+ # @param [String] id Connection unique identifier
261
+ #
262
+ # @example
263
+ # WorkOS::SSO.delete_connection(id: 'conn_02DRA1XNSJDZ19A31F183ECQW9')
264
+ # => true
265
+ #
266
+ # @return [Bool] - returns `true` if successful
267
+ sig { params(id: String).returns(T::Boolean) }
268
+ def delete_connection(id:)
269
+ request = delete_request(
270
+ auth: true,
271
+ path: "/connections/#{id}",
272
+ )
273
+
274
+ response = execute_request(request: request)
275
+
276
+ response.is_a? Net::HTTPSuccess
277
+ end
278
+
171
279
  private
172
280
 
173
281
  sig do
@@ -187,7 +295,6 @@ module WorkOS
187
295
  " `provider` must be in #{PROVIDERS}"
188
296
  end
189
297
 
190
- # rubocop:disable Metrics/MethodLength
191
298
  sig { params(response: Net::HTTPResponse).void }
192
299
  def check_and_raise_profile_error(response:)
193
300
  begin
@@ -206,7 +313,6 @@ module WorkOS
206
313
  request_id: request_id,
207
314
  )
208
315
  end
209
- # rubocop:enable Metrics/MethodLength
210
316
  end
211
317
  end
212
318
  end