workos 0.9.2 → 0.10.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 +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +15 -15
- data/docs/WorkOS/SSO.html +235 -235
- data/docs/file.README.html +20 -20
- data/lib/workos/client.rb +22 -1
- data/lib/workos/passwordless.rb +0 -2
- data/lib/workos/portal.rb +0 -6
- data/lib/workos/profile.rb +2 -2
- data/lib/workos/sso.rb +119 -13
- data/lib/workos/version.rb +1 -1
- data/spec/lib/workos/sso_spec.rb +198 -7
- data/spec/support/fixtures/vcr_cassettes/audit_trail/get_events.yml +2 -2
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories.yml +1 -1
- data/spec/support/fixtures/vcr_cassettes/directory_sync/list_directories_with_domain_param.yml +1 -1
- data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_invalid_id.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/delete_connection_with_valid_id.yml +70 -0
- data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_invalid_id.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/get_connection_with_valid_id.yml +74 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_after_param.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_before_param.yml +73 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_connection_type_param.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_domain_param.yml +72 -0
- data/spec/support/fixtures/vcr_cassettes/sso/list_connections_with_limit_param.yml +72 -0
- metadata +23 -3
data/docs/file.README.html
CHANGED
@@ -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
|
— 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> »
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
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:,
|
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's company domain, without protocol (ex. <code>example.com</code>)</p>
|
152
152
|
</li><li>
|
153
|
-
<p><code>
|
153
|
+
<p><code>client_id</code> (string) — your application'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: '/docs'}</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
|
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=${
|
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'>'</span><span class='tstring_content'>example.com</span><span class='tstring_end'>'</span></span>
|
167
|
-
<span class='const'>
|
167
|
+
<span class='const'>CLIENT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>{clientId}</span><span class='tstring_end'>'</span></span>
|
168
168
|
<span class='const'>REDIRECT_URI</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>http://localhost:4567/callback</span><span class='tstring_end'>'</span></span>
|
169
169
|
|
170
170
|
<span class='id identifier rubyid_get'>get</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/auth</span><span class='tstring_end'>'</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'>
|
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={
|
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'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:,
|
187
|
+
<pre class="code ruby"><code class="ruby">WorkOS::SSO.profile(code:, client_id:)</h4>
|
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's profile is sent</p>
|
197
197
|
</li><li>
|
198
|
-
<p><code>
|
198
|
+
<p><code>client_id</code> (string) — your application'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'>'</span><span class='tstring_content'>example.com</span><span class='tstring_end'>'</span></span>
|
216
|
-
<span class='const'>
|
216
|
+
<span class='const'>CLIENT_ID</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>{clientId}</span><span class='tstring_end'>'</span></span>
|
217
217
|
<span class='const'>REDIRECT_URI</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>http://localhost:4567/callback</span><span class='tstring_end'>'</span></span>
|
218
218
|
|
219
219
|
<span class='id identifier rubyid_get'>get</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/auth</span><span class='tstring_end'>'</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'>
|
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'>'</span><span class='tstring_content'>/callback</span><span class='tstring_end'>'</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'>'</span><span class='tstring_content'>code</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span>
|
232
|
-
<span class='label'>
|
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/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'
|
data/lib/workos/passwordless.rb
CHANGED
@@ -36,7 +36,6 @@ module WorkOS
|
|
36
36
|
).returns(WorkOS::Types::PasswordlessSessionStruct)
|
37
37
|
end
|
38
38
|
|
39
|
-
# rubocop:disable Metrics/MethodLength
|
40
39
|
def create_session(options)
|
41
40
|
response = execute_request(
|
42
41
|
request: post_request(
|
@@ -55,7 +54,6 @@ module WorkOS
|
|
55
54
|
link: hash['link'],
|
56
55
|
)
|
57
56
|
end
|
58
|
-
# rubocop:enable Metrics/MethodLength
|
59
57
|
|
60
58
|
# Send a Passwordless Session via email.
|
61
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)
|
data/lib/workos/profile.rb
CHANGED
@@ -49,7 +49,7 @@ module WorkOS
|
|
49
49
|
|
50
50
|
private
|
51
51
|
|
52
|
-
# rubocop:disable Metrics/AbcSize
|
52
|
+
# rubocop:disable Metrics/AbcSize
|
53
53
|
sig { params(json_string: String).returns(WorkOS::Types::ProfileStruct) }
|
54
54
|
def parse_json(json_string)
|
55
55
|
hash = JSON.parse(json_string, symbolize_names: true)
|
@@ -65,6 +65,6 @@ module WorkOS
|
|
65
65
|
raw_attributes: hash[:profile][:raw_attributes],
|
66
66
|
)
|
67
67
|
end
|
68
|
-
# rubocop:enable Metrics/AbcSize
|
68
|
+
# rubocop:enable Metrics/AbcSize
|
69
69
|
end
|
70
70
|
end
|
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
|
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]
|
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
|
-
#
|
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
|
-
|
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:
|
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]
|
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
|
-
#
|
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
|
101
|
-
|
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:
|
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
|