workos 5.9.0 → 5.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/Gemfile.lock +1 -1
- data/lib/workos/client.rb +8 -0
- data/lib/workos/errors.rb +4 -0
- data/lib/workos/organizations.rb +26 -0
- data/lib/workos/role.rb +36 -0
- data/lib/workos/version.rb +1 -1
- data/lib/workos.rb +2 -0
- data/spec/lib/workos/organizations_spec.rb +18 -0
- data/spec/lib/workos/user_management_spec.rb +14 -0
- data/spec/support/fixtures/vcr_cassettes/organization/list_organization_roles.yml +82 -0
- data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/unverified.yml +82 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83c350d6c017c0cf423adb02925391b3a5e11d622479d76073c3c6372e526105
|
4
|
+
data.tar.gz: 83a8e5700dc7a3d47d37a84de01f866997a260eeaf96c55fd40318a30195a7d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48bcc853e186de15ce9e71e98415d801e412540a43fe1711ab97264b3419ce7dc7c1ec6095411cc7093bcb788b02ab51efe4689c0a79993f921e037ce0a7954c
|
7
|
+
data.tar.gz: f52aec8320aa98bb11ec114ffccb51a82218c7581cac202f74facfe943e96633b90262a67c37ed0677c73f4f73bb3bdd77760a67471c80a18ca878e0d7dffb55
|
data/Gemfile.lock
CHANGED
data/lib/workos/client.rb
CHANGED
@@ -109,6 +109,14 @@ module WorkOS
|
|
109
109
|
http_status: http_status,
|
110
110
|
request_id: response['x-request-id'],
|
111
111
|
)
|
112
|
+
when 403
|
113
|
+
raise ForbiddenRequestError.new(
|
114
|
+
message: json['message'],
|
115
|
+
http_status: http_status,
|
116
|
+
request_id: response['x-request-id'],
|
117
|
+
code: json['code'],
|
118
|
+
data: json,
|
119
|
+
)
|
112
120
|
when 404
|
113
121
|
raise NotFoundError.new(
|
114
122
|
message: json['message'],
|
data/lib/workos/errors.rb
CHANGED
@@ -64,6 +64,10 @@ module WorkOS
|
|
64
64
|
# parameters.
|
65
65
|
class InvalidRequestError < WorkOSError; end
|
66
66
|
|
67
|
+
# ForbiddenError is raised when a request is forbidden, likely due to missing a step
|
68
|
+
# (i.e. verifying email ownership before authenticating).
|
69
|
+
class ForbiddenRequestError < WorkOSError; end
|
70
|
+
|
67
71
|
# SignatureVerificationError is raised when the signature verification for a
|
68
72
|
# webhook fails
|
69
73
|
class SignatureVerificationError < WorkOSError; end
|
data/lib/workos/organizations.rb
CHANGED
@@ -180,6 +180,32 @@ module WorkOS
|
|
180
180
|
response.is_a? Net::HTTPSuccess
|
181
181
|
end
|
182
182
|
|
183
|
+
# Retrieve a list of roles for the given organization.
|
184
|
+
#
|
185
|
+
# @param [String] organizationId The ID of the organization to fetch roles for.
|
186
|
+
def list_organization_roles(organization_id:)
|
187
|
+
response = execute_request(
|
188
|
+
request: get_request(
|
189
|
+
path: "/organizations/#{organization_id}/roles",
|
190
|
+
auth: true,
|
191
|
+
),
|
192
|
+
)
|
193
|
+
|
194
|
+
parsed_response = JSON.parse(response.body)
|
195
|
+
|
196
|
+
roles = parsed_response['data'].map do |role|
|
197
|
+
WorkOS::Role.new(role.to_json)
|
198
|
+
end
|
199
|
+
|
200
|
+
WorkOS::Types::ListStruct.new(
|
201
|
+
data: roles,
|
202
|
+
list_metadata: {
|
203
|
+
after: nil,
|
204
|
+
before: nil,
|
205
|
+
},
|
206
|
+
)
|
207
|
+
end
|
208
|
+
|
183
209
|
private
|
184
210
|
|
185
211
|
def check_and_raise_organization_error(response:)
|
data/lib/workos/role.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WorkOS
|
4
|
+
# The Role class provides a lightweight wrapper around
|
5
|
+
# a WorkOS Role resource. This class is not meant to be instantiated
|
6
|
+
# in user space, and is instantiated internally but exposed.
|
7
|
+
class Role
|
8
|
+
include HashProvider
|
9
|
+
|
10
|
+
attr_accessor :id, :name, :slug, :description, :type, :created_at, :updated_at
|
11
|
+
|
12
|
+
def initialize(json)
|
13
|
+
hash = JSON.parse(json, symbolize_names: true)
|
14
|
+
|
15
|
+
@id = hash[:id]
|
16
|
+
@name = hash[:name]
|
17
|
+
@slug = hash[:slug]
|
18
|
+
@description = hash[:description]
|
19
|
+
@type = hash[:type]
|
20
|
+
@created_at = hash[:created_at]
|
21
|
+
@updated_at = hash[:updated_at]
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json(*)
|
25
|
+
{
|
26
|
+
id: id,
|
27
|
+
name: name,
|
28
|
+
slug: slug,
|
29
|
+
description: description,
|
30
|
+
type: type,
|
31
|
+
created_at: created_at,
|
32
|
+
updated_at: updated_at,
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/workos/version.rb
CHANGED
data/lib/workos.rb
CHANGED
@@ -71,6 +71,7 @@ module WorkOS
|
|
71
71
|
autoload :Profile, 'workos/profile'
|
72
72
|
autoload :ProfileAndToken, 'workos/profile_and_token'
|
73
73
|
autoload :RefreshAuthenticationResponse, 'workos/refresh_authentication_response'
|
74
|
+
autoload :Role, 'workos/role'
|
74
75
|
autoload :Session, 'workos/session'
|
75
76
|
autoload :SSO, 'workos/sso'
|
76
77
|
autoload :Types, 'workos/types'
|
@@ -87,6 +88,7 @@ module WorkOS
|
|
87
88
|
autoload :APIError, 'workos/errors'
|
88
89
|
autoload :AuthenticationError, 'workos/errors'
|
89
90
|
autoload :InvalidRequestError, 'workos/errors'
|
91
|
+
autoload :ForbiddenRequestError, 'workos/errors'
|
90
92
|
autoload :SignatureVerificationError, 'workos/errors'
|
91
93
|
autoload :TimeoutError, 'workos/errors'
|
92
94
|
autoload :NotFoundError, 'workos/errors'
|
@@ -323,4 +323,22 @@ describe WorkOS::Organizations do
|
|
323
323
|
end
|
324
324
|
end
|
325
325
|
end
|
326
|
+
|
327
|
+
describe '.list_organization_roles' do
|
328
|
+
context 'with no options' do
|
329
|
+
it 'returns roles for organization' do
|
330
|
+
expected_metadata = {
|
331
|
+
after: nil,
|
332
|
+
before: nil,
|
333
|
+
}
|
334
|
+
|
335
|
+
VCR.use_cassette 'organization/list_organization_roles' do
|
336
|
+
roles = described_class.list_organization_roles(organization_id: 'org_01JEXP6Z3X7HE4CB6WQSH9ZAFE')
|
337
|
+
|
338
|
+
expect(roles.data.size).to eq(7)
|
339
|
+
expect(roles.list_metadata).to eq(expected_metadata)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
326
344
|
end
|
@@ -404,6 +404,20 @@ describe WorkOS::UserManagement do
|
|
404
404
|
end
|
405
405
|
end
|
406
406
|
end
|
407
|
+
|
408
|
+
context 'with an unverified user' do
|
409
|
+
it 'raises a ForbiddenRequestError' do
|
410
|
+
VCR.use_cassette('user_management/authenticate_with_password/unverified') do
|
411
|
+
expect do
|
412
|
+
WorkOS::UserManagement.authenticate_with_password(
|
413
|
+
email: 'unverified@workos.app',
|
414
|
+
password: '7YtYic00VWcXatPb',
|
415
|
+
client_id: 'client_123',
|
416
|
+
)
|
417
|
+
end.to raise_error(WorkOS::ForbiddenRequestError, /Email ownership must be verified before authentication/)
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
407
421
|
end
|
408
422
|
|
409
423
|
describe '.authenticate_with_code' do
|
@@ -0,0 +1,82 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.workos.com/organizations/org_01JEXP6Z3X7HE4CB6WQSH9ZAFE/roles
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ""
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
User-Agent:
|
17
|
+
- WorkOS; ruby/3.3.6; arm64-darwin23; v5.9.0
|
18
|
+
Authorization:
|
19
|
+
- Bearer <API_KEY>
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Date:
|
26
|
+
- Mon, 23 Dec 2024 20:23:07 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Cf-Ray:
|
34
|
+
- 8f6b114e5e60c96a-IAD
|
35
|
+
Cf-Cache-Status:
|
36
|
+
- DYNAMIC
|
37
|
+
Etag:
|
38
|
+
- W/"6b6-bZ2pS5djCBrbcATBSFlbZ90PHB8"
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=15552000; includeSubDomains
|
41
|
+
Vary:
|
42
|
+
- Origin, Accept-Encoding
|
43
|
+
Access-Control-Allow-Credentials:
|
44
|
+
- "true"
|
45
|
+
Content-Security-Policy:
|
46
|
+
- "default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self'
|
47
|
+
https: data:;frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src
|
48
|
+
'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests"
|
49
|
+
Expect-Ct:
|
50
|
+
- max-age=0
|
51
|
+
Referrer-Policy:
|
52
|
+
- no-referrer
|
53
|
+
X-Content-Type-Options:
|
54
|
+
- nosniff
|
55
|
+
X-Dns-Prefetch-Control:
|
56
|
+
- "off"
|
57
|
+
X-Download-Options:
|
58
|
+
- noopen
|
59
|
+
X-Frame-Options:
|
60
|
+
- SAMEORIGIN
|
61
|
+
X-Permitted-Cross-Domain-Policies:
|
62
|
+
- none
|
63
|
+
X-Request-Id:
|
64
|
+
- a8db37d7-9244-4e2a-b183-b5e2a67d8104
|
65
|
+
X-Xss-Protection:
|
66
|
+
- "0"
|
67
|
+
Server:
|
68
|
+
- cloudflare
|
69
|
+
body:
|
70
|
+
encoding: ASCII-8BIT
|
71
|
+
string:
|
72
|
+
'{"object":"list","data":[{"object":"role","id":"role_01HS1C7GRJE08PBR3M6Y0ZYGDZ","description":"Write
|
73
|
+
access to every resource available","name":"Admin","slug":"admin","type":"EnvironmentRole","created_at":"2024-03-15T15:38:29.521Z","updated_at":"2024-11-14T17:08:00.556Z"},{"object":"role","id":"role_01JA8GJZRDSZEB9289DQXJ3N9Z","description":"","name":"Billing
|
74
|
+
Manager","slug":"billing","type":"EnvironmentRole","created_at":"2024-10-15T16:36:11.653Z","updated_at":"2024-12-19T21:27:01.286Z"},{"object":"role","id":"role_01HSBH4R6RX0V86S3R590NNZW2","description":"Developer
|
75
|
+
role","name":"Developer","slug":"developer","type":"EnvironmentRole","created_at":"2024-03-19T14:16:46.038Z","updated_at":"2024-03-19T14:16:46.038Z"},{"object":"role","id":"role_01HS4GDWJ8T6NQPTX2D0R5KBHN","description":"Edit
|
76
|
+
and view access to non-critical resources","name":"Editor","slug":"editor","type":"EnvironmentRole","created_at":"2024-03-16T20:49:35.815Z","updated_at":"2024-03-16T20:52:19.410Z"},{"object":"role","id":"role_01HRFZE22WS2MGX6EWAG2JX6NW","description":"The
|
77
|
+
default user role","name":"Member","slug":"member","type":"EnvironmentRole","created_at":"2024-03-08T21:27:47.034Z","updated_at":"2024-08-14T00:27:46.265Z"},{"object":"role","id":"role_01JEYJ2Z5MYG0TZYTDF02MW11N","description":"Manage
|
78
|
+
billing for organization.","name":"Billing manager","slug":"org-billing-manager","type":"OrganizationRole","created_at":"2024-12-12T23:08:28.712Z","updated_at":"2024-12-12T23:08:28.712Z"},{"object":"role","id":"role_01JF0B7MQ9X414WQRAQMQYE1GS","description":"","name":"Platform
|
79
|
+
Manager","slug":"org-platform-manager","type":"OrganizationRole","created_at":"2024-12-13T15:47:10.692Z","updated_at":"2024-12-13T15:47:10.692Z"}]}'
|
80
|
+
http_version:
|
81
|
+
recorded_at: Mon, 23 Dec 2024 20:23:07 GMT
|
82
|
+
recorded_with: VCR 5.0.0
|
data/spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/unverified.yml
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.workos.com/user_management/authenticate
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string:
|
9
|
+
'{"client_id":"client_123","client_secret":"<API_KEY>","email":"unverified@workos.app","password":"7YtYic00VWcXatPb","ip_address":"200.240.210.16","user_agent":"Mozilla/5.0
|
10
|
+
(Macintosh; Intel Mac OS X 10_15_7) Chrome/108.0.0.0 Safari/537.36","grant_type":"password"}'
|
11
|
+
headers:
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
User-Agent:
|
19
|
+
- WorkOS; ruby/3.0.2; arm64-darwin21; v2.16.0
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 403
|
23
|
+
message: Email ownership must be verified before authentication.
|
24
|
+
headers:
|
25
|
+
Date:
|
26
|
+
- Tue, 29 Aug 2023 00:24:25 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Transfer-Encoding:
|
30
|
+
- chunked
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Cf-Ray:
|
34
|
+
- 7fe0a6a27b0bc39c-SEA
|
35
|
+
Cf-Cache-Status:
|
36
|
+
- DYNAMIC
|
37
|
+
Etag:
|
38
|
+
- W/"16e-hoaHaR0EhmAH7TaNBOF8B2OHJq4"
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=15552000; includeSubDomains
|
41
|
+
Vary:
|
42
|
+
- Origin, Accept-Encoding
|
43
|
+
Via:
|
44
|
+
- 1.1 spaces-router (devel)
|
45
|
+
Access-Control-Allow-Credentials:
|
46
|
+
- 'true'
|
47
|
+
Content-Security-Policy:
|
48
|
+
- "default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self'
|
49
|
+
https: data:;frame-ancestors 'self';img-src 'self' data:;object-src 'none';script-src
|
50
|
+
'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests"
|
51
|
+
Expect-Ct:
|
52
|
+
- max-age=0
|
53
|
+
Referrer-Policy:
|
54
|
+
- no-referrer
|
55
|
+
X-Content-Type-Options:
|
56
|
+
- nosniff
|
57
|
+
X-Dns-Prefetch-Control:
|
58
|
+
- 'off'
|
59
|
+
X-Download-Options:
|
60
|
+
- noopen
|
61
|
+
X-Frame-Options:
|
62
|
+
- SAMEORIGIN
|
63
|
+
X-Permitted-Cross-Domain-Policies:
|
64
|
+
- none
|
65
|
+
X-Request-Id:
|
66
|
+
- 62990367-ddaf-46b3-a32f-38fc4f29d581
|
67
|
+
X-Xss-Protection:
|
68
|
+
- '0'
|
69
|
+
Set-Cookie:
|
70
|
+
- __cf_bm=IiwoT1XAlPdVWj334oRTocU7zZyvKgYw61o0UoA7GtE-1693268665-0-AZTn/iGDfGV6R5j3aj7lcPod7FB9P3cbHc9pD1oN/U5ZmnUYvpCecp6AL+8p/+/bMuwwGqXGNMSa/eIpa0TVm+I=;
|
71
|
+
path=/; expires=Tue, 29-Aug-23 00:54:25 GMT; domain=.workos.com; HttpOnly;
|
72
|
+
Secure; SameSite=None
|
73
|
+
- __cfruid=beafd87202de7b7d34fd4a1af55696cb5d19364d-1693268665; path=/; domain=.workos.com;
|
74
|
+
HttpOnly; Secure; SameSite=None
|
75
|
+
Server:
|
76
|
+
- cloudflare
|
77
|
+
body:
|
78
|
+
encoding: ASCII-8BIT
|
79
|
+
string: '{"code":"email_verification_required", "message":"Email ownership must be verified before authentication.", "email":"unverified@workos.app", "pending_authentication_token":"RWx94aFHwanPOebv7tKbBkJm0", "email_verification_id":"email_verification_01JG43A0WYAFAPHMNBV5XF2R4M"}'
|
80
|
+
http_version:
|
81
|
+
recorded_at: Tue, 29 Aug 2023 00:24:25 GMT
|
82
|
+
recorded_with: VCR 5.0.0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WorkOS
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: encryptor
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- lib/workos/profile.rb
|
166
166
|
- lib/workos/profile_and_token.rb
|
167
167
|
- lib/workos/refresh_authentication_response.rb
|
168
|
+
- lib/workos/role.rb
|
168
169
|
- lib/workos/session.rb
|
169
170
|
- lib/workos/sso.rb
|
170
171
|
- lib/workos/types.rb
|
@@ -267,6 +268,7 @@ files:
|
|
267
268
|
- spec/support/fixtures/vcr_cassettes/organization/get.yml
|
268
269
|
- spec/support/fixtures/vcr_cassettes/organization/get_invalid.yml
|
269
270
|
- spec/support/fixtures/vcr_cassettes/organization/list.yml
|
271
|
+
- spec/support/fixtures/vcr_cassettes/organization/list_organization_roles.yml
|
270
272
|
- spec/support/fixtures/vcr_cassettes/organization/update.yml
|
271
273
|
- spec/support/fixtures/vcr_cassettes/organization/update_without_name.yml
|
272
274
|
- spec/support/fixtures/vcr_cassettes/passwordless/create_session.yml
|
@@ -300,6 +302,7 @@ files:
|
|
300
302
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_organization_selection/invalid.yml
|
301
303
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_organization_selection/valid.yml
|
302
304
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/invalid.yml
|
305
|
+
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/unverified.yml
|
303
306
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/valid.yml
|
304
307
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_refresh_code/invalid.yml
|
305
308
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_refresh_token/valid.yml
|
@@ -484,6 +487,7 @@ test_files:
|
|
484
487
|
- spec/support/fixtures/vcr_cassettes/organization/get.yml
|
485
488
|
- spec/support/fixtures/vcr_cassettes/organization/get_invalid.yml
|
486
489
|
- spec/support/fixtures/vcr_cassettes/organization/list.yml
|
490
|
+
- spec/support/fixtures/vcr_cassettes/organization/list_organization_roles.yml
|
487
491
|
- spec/support/fixtures/vcr_cassettes/organization/update.yml
|
488
492
|
- spec/support/fixtures/vcr_cassettes/organization/update_without_name.yml
|
489
493
|
- spec/support/fixtures/vcr_cassettes/passwordless/create_session.yml
|
@@ -517,6 +521,7 @@ test_files:
|
|
517
521
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_organization_selection/invalid.yml
|
518
522
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_organization_selection/valid.yml
|
519
523
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/invalid.yml
|
524
|
+
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/unverified.yml
|
520
525
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_password/valid.yml
|
521
526
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_refresh_code/invalid.yml
|
522
527
|
- spec/support/fixtures/vcr_cassettes/user_management/authenticate_with_refresh_token/valid.yml
|