workos 5.8.0 → 5.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0afe2a59cbc6559cee74fe894ad0ed632b6788955377949f87c641a3550fff92
4
- data.tar.gz: 1725783e695045041a65334679db26c2fb396f1e79a3c4d18d7491d91d479756
3
+ metadata.gz: 47230d64b8cf21f97c3c7d0e9d0c7e90fa7c4f73071744532c6f41d10a27cde3
4
+ data.tar.gz: afe55ccfecaccf2685f6317b7e5d1131e7f92450f41419ab564f6e69faea1876
5
5
  SHA512:
6
- metadata.gz: 626069aef80ea5cf1b3254679fb7f7c9054fe7f908c464521e42c566186c21170f5a3187e98c59d6f1f209d107e53995facb58763965042ce257d2e4cd8f5d63
7
- data.tar.gz: 0f941008d87d91b19bbd5829cf79580df7cabb9e3d37891aa3016fca9e4af844ecd8a30f3b4e6e567d6a47ece9249b6e6da02eda157928bd2ee8c5d45c6404d2
6
+ metadata.gz: cd786ea513509e1a1a692143c4af0ae2db289a4ef62bcdea139f854b735334e7768324b4ed8f5fbd1317648149a10bdcf69fc99547cf62c3282e183e4108215f
7
+ data.tar.gz: 295e13fab2ab3d3adcf6828f0259387de68b50256d575e737c5d00343fad62ee2c3096e235cc0cd687582f6f20076b3666e908f2313772e5b4a2160abd788a81
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- workos (5.8.0)
4
+ workos (5.9.0)
5
5
  encryptor (~> 3.0)
6
6
  jwt (~> 2.8)
7
7
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkOS
4
+ module Types
5
+ # The WidgetScope constants are declarations of a fixed set of values for
6
+ # scopes while generating a widget token.
7
+ module WidgetScope
8
+ USERS_TABLE_MANAGE = 'widgets:users-table:manage'
9
+
10
+ ALL = [USERS_TABLE_MANAGE].freeze
11
+ end
12
+ end
13
+ end
data/lib/workos/types.rb CHANGED
@@ -7,5 +7,6 @@ module WorkOS
7
7
  autoload :Intent, 'workos/types/intent'
8
8
  autoload :ListStruct, 'workos/types/list_struct'
9
9
  autoload :PasswordlessSessionStruct, 'workos/types/passwordless_session_struct'
10
+ autoload :WidgetScope, 'workos/types/widget_scope'
10
11
  end
11
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkOS
4
- VERSION = '5.8.0'
4
+ VERSION = '5.9.0'
5
5
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ module WorkOS
6
+ # The Widgets module provides resource methods for working with the Widgets APIs
7
+ module Widgets
8
+ class << self
9
+ include Client
10
+
11
+ WIDGET_SCOPES = WorkOS::Types::WidgetScope::ALL
12
+
13
+ # Generate a widget token.
14
+ #
15
+ # @param [String] organization_id The ID of the organization to generate the token for.
16
+ # @param [String] user_id The ID of the user to generate the token for.
17
+ # @param [WidgetScope[]] The scopes to generate the token for.
18
+ def get_token(organization_id:, user_id:, scopes:)
19
+ validate_scopes(scopes)
20
+
21
+ request = post_request(
22
+ auth: true,
23
+ body: {
24
+ organization_id: organization_id,
25
+ user_id: user_id,
26
+ scopes: scopes,
27
+ },
28
+ path: '/widgets/token',
29
+ )
30
+
31
+ response = execute_request(request: request)
32
+
33
+ JSON.parse(response.body)['token']
34
+ end
35
+
36
+ private
37
+
38
+ def validate_scopes(scopes)
39
+ return if scopes.all? { |scope| WIDGET_SCOPES.include?(scope) }
40
+
41
+ raise ArgumentError, 'scopes contains an invalid value.' \
42
+ " Every item in `scopes` must be in #{WIDGET_SCOPES}"
43
+ end
44
+ end
45
+ end
46
+ end
data/lib/workos.rb CHANGED
@@ -81,6 +81,7 @@ module WorkOS
81
81
  autoload :VerifyChallenge, 'workos/verify_challenge'
82
82
  autoload :Webhook, 'workos/webhook'
83
83
  autoload :Webhooks, 'workos/webhooks'
84
+ autoload :Widgets, 'workos/widgets'
84
85
 
85
86
  # Errors
86
87
  autoload :APIError, 'workos/errors'
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe WorkOS::Widgets do
4
+ it_behaves_like 'client'
5
+
6
+ describe '.get_token' do
7
+ let(:organization_id) { 'org_01JCP9G67MNAH0KC4B72XZ67M7' }
8
+ let(:user_id) { 'user_01JCP9H4SHS4N3J6XTKDT7JNPE' }
9
+
10
+ describe 'with a valid organization_id and user_id and scopes' do
11
+ it 'returns a widget token' do
12
+ VCR.use_cassette 'widgets/get_token' do
13
+ token = described_class.get_token(
14
+ organization_id: organization_id,
15
+ user_id: user_id,
16
+ scopes: ['widgets:users-table:manage'],
17
+ )
18
+
19
+ expect(token).to start_with('eyJhbGciOiJSUzI1NiIsImtpZ')
20
+ end
21
+ end
22
+ end
23
+
24
+ describe 'with an invalid organization_id' do
25
+ it 'raises an error' do
26
+ VCR.use_cassette 'widgets/get_token_invalid_organization_id' do
27
+ expect do
28
+ described_class.get_token(
29
+ organization_id: 'bogus-id',
30
+ user_id: user_id,
31
+ scopes: ['widgets:users-table:manage'],
32
+ )
33
+ end.to raise_error(
34
+ WorkOS::NotFoundError,
35
+ /Organization not found: 'bogus-id'/,
36
+ )
37
+ end
38
+ end
39
+ end
40
+
41
+ describe 'with an invalid user_id' do
42
+ it 'raises an error' do
43
+ VCR.use_cassette 'widgets/get_token_invalid_user_id' do
44
+ expect do
45
+ described_class.get_token(
46
+ organization_id: organization_id,
47
+ user_id: 'bogus-id',
48
+ scopes: ['widgets:users-table:manage'],
49
+ )
50
+ end.to raise_error(
51
+ WorkOS::NotFoundError,
52
+ /User not found: 'bogus-id'/,
53
+ )
54
+ end
55
+ end
56
+ end
57
+
58
+ describe 'with invalid scopes' do
59
+ it 'raises an error' do
60
+ expect do
61
+ described_class.get_token(
62
+ organization_id: organization_id,
63
+ user_id: user_id,
64
+ scopes: ['bogus-scope'],
65
+ )
66
+ end.to raise_error(
67
+ ArgumentError,
68
+ /scopes contains an invalid value/,
69
+ )
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,82 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.workos.com/widgets/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"organization_id":"org_01JCP9G67MNAH0KC4B72XZ67M7","user_id":"user_01JCP9H4SHS4N3J6XTKDT7JNPE","scopes":["widgets:users-table:manage"]}'
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.8.0
18
+ Authorization:
19
+ - Bearer <API_KEY>
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Date:
26
+ - Thu, 14 Nov 2024 21:51:34 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '791'
31
+ Connection:
32
+ - keep-alive
33
+ Cf-Ray:
34
+ - 8e2a394198f8c9b8-IAD
35
+ Cf-Cache-Status:
36
+ - DYNAMIC
37
+ Etag:
38
+ - W/"317-Nylo8f8lWbsA0UUWqqV59mFy5jo"
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
+ - bf98d35e-d9ca-437f-b937-150e937af0f1
65
+ X-Xss-Protection:
66
+ - '0'
67
+ Set-Cookie:
68
+ - __cf_bm=GsR9Veicl9ZRIR1pUSamJ5m95HmklSbWNwtyp_fSpB4-1731621094-1.0.1.1-VW09qjPlT4T.AGwnsHxe7p_A.Onr9Oe7YnxumCz7B9XmzqYbLz9fx7cF6Qtw3KW0PIshpAVkluIsGWSCJQ5AjQ;
69
+ path=/; expires=Thu, 14-Nov-24 22:21:34 GMT; domain=.workos.com; HttpOnly;
70
+ Secure; SameSite=None
71
+ - __cfruid=022c638e9216cb6be687ace27cb356d48cbd4256-1731621094; path=/; domain=.workos.com;
72
+ HttpOnly; Secure; SameSite=None
73
+ - _cfuvid=kczJ.JXlRroyPs5B7UjNUynSmsUjYTWP_jcLNj2iiuM-1731621094755-0.0.1.1-604800000;
74
+ path=/; domain=.workos.com; HttpOnly; Secure; SameSite=None
75
+ Server:
76
+ - cloudflare
77
+ body:
78
+ encoding: UTF-8
79
+ string: '{"token":"eyJhbGciOiJSUzI1NiIsImtpZCI6InNzb19vaWRjX2tleV9wYWlyXzAxSFY3SlpGWEtQOVhCQjc2NjY0TkdUQlpYIn0.eyJhdWQiOiJodHRwczovL2FwaS53b3Jrb3MuY29tIiwiaXNzIjoiaHR0cHM6Ly9hcGkud29ya29zLmNvbSIsInN1YiI6InVzZXJfMDFKQ1A5SDRTSFM0TjNKNlhUS0RUN0pOUEUiLCJqdGkiOiIwMUpDUEFKMUFHWDVESzFNM0hDQTk5MFM1SiIsIm9yZ19pZCI6Im9yZ18wMUpDUDlHNjdNTkFIMEtDNEI3MlhaNjdNNyIsInBlcm1pc3Npb25zIjpbInVzZXJzOm1hbmFnZSIsInVzZXJzOnZpZXciXSwiZXhwIjoxNzMxNjI0Njk0LCJpYXQiOjE3MzE2MjEwOTR9.CTYliFAGFjw-_Lyla-yVBOUAn1ZqU-J7aOdWhAW8fiEsNMz73Fb5nRACa0PFWBE3HK1a8waV-S5lBCGHyxgYOaew5URNnlYXVwlgpKwujHDrW47FrYpxkyxVovY9z9SqDDNRHWBqJM3mH_4Fn9jaHwAVT0SPJrJ7Q4-jxfTc0_sZMR7RVJaBIXPEU8og6Zwc84Gx-9A-mBUA3PPUXfaa8JrCr5OGc482vbD1rF5sjk0jx_FovHrlI3qRo5nkQ3_5WEi7LzdxSPviITxY1-dtm0HbeULz8IL7Ic5O4Ok4lB2c8s8XoZT1JqUMmEHfugkWyQ4juN5aHpmf6ux8cJSJWg"}'
80
+ http_version:
81
+ recorded_at: Thu, 14 Nov 2024 21:51:34 GMT
82
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,74 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.workos.com/widgets/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"organization_id":"bogus-id","user_id":"user_01JCP9H4SHS4N3J6XTKDT7JNPE","scopes":["widgets:users-table:manage"]}'
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.8.0
18
+ Authorization:
19
+ - Bearer <API_KEY>
20
+ response:
21
+ status:
22
+ code: 404
23
+ message: Not Found
24
+ headers:
25
+ Date:
26
+ - Thu, 14 Nov 2024 22:02:40 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Cf-Ray:
34
+ - 8e2a49858b5a7fa2-IAD
35
+ Cf-Cache-Status:
36
+ - DYNAMIC
37
+ Etag:
38
+ - W/"62-XNhANyOqo4doKt47ORHxpVuFTYg"
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
+ - 3d383216-51fe-42cd-87e2-7fee32719353
65
+ X-Xss-Protection:
66
+ - '0'
67
+ Server:
68
+ - cloudflare
69
+ body:
70
+ encoding: ASCII-8BIT
71
+ string: '{"message":"Organization not found: ''bogus-id''.","code":"entity_not_found","entity_id":"bogus-id"}'
72
+ http_version:
73
+ recorded_at: Thu, 14 Nov 2024 22:02:40 GMT
74
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,74 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.workos.com/widgets/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"organization_id":"org_01JCP9G67MNAH0KC4B72XZ67M7","user_id":"bogus-id","scopes":["widgets:users-table:manage"]}'
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.8.0
18
+ Authorization:
19
+ - Bearer <API_KEY>
20
+ response:
21
+ status:
22
+ code: 404
23
+ message: Not Found
24
+ headers:
25
+ Date:
26
+ - Thu, 14 Nov 2024 22:02:46 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Cf-Ray:
34
+ - 8e2a49a82b31c54f-IAD
35
+ Cf-Cache-Status:
36
+ - DYNAMIC
37
+ Etag:
38
+ - W/"5a-TOigA+IvFyAtHvUdIXFXZWRdn8I"
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
+ - 0aeb3b90-0fd7-4de9-8d76-3d0e340ed583
65
+ X-Xss-Protection:
66
+ - '0'
67
+ Server:
68
+ - cloudflare
69
+ body:
70
+ encoding: ASCII-8BIT
71
+ string: '{"message":"User not found: ''bogus-id''.","code":"entity_not_found","entity_id":"bogus-id"}'
72
+ http_version:
73
+ recorded_at: Thu, 14 Nov 2024 22:02:46 GMT
74
+ 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.8.0
4
+ version: 5.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - WorkOS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-16 00:00:00.000000000 Z
11
+ date: 2024-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: encryptor
@@ -172,6 +172,7 @@ files:
172
172
  - lib/workos/types/list_struct.rb
173
173
  - lib/workos/types/passwordless_session_struct.rb
174
174
  - lib/workos/types/provider.rb
175
+ - lib/workos/types/widget_scope.rb
175
176
  - lib/workos/user.rb
176
177
  - lib/workos/user_and_token.rb
177
178
  - lib/workos/user_management.rb
@@ -180,6 +181,7 @@ files:
180
181
  - lib/workos/version.rb
181
182
  - lib/workos/webhook.rb
182
183
  - lib/workos/webhooks.rb
184
+ - lib/workos/widgets.rb
183
185
  - spec/lib/workos/audit_logs_spec.rb
184
186
  - spec/lib/workos/client.rb
185
187
  - spec/lib/workos/configuration_spec.rb
@@ -194,6 +196,7 @@ files:
194
196
  - spec/lib/workos/sso_spec.rb
195
197
  - spec/lib/workos/user_management_spec.rb
196
198
  - spec/lib/workos/webhooks_spec.rb
199
+ - spec/lib/workos/widgets_spec.rb
197
200
  - spec/spec_helper.rb
198
201
  - spec/support/fixtures/vcr_cassettes/audit_logs/create_event.yml
199
202
  - spec/support/fixtures/vcr_cassettes/audit_logs/create_event_custom_idempotency_key.yml
@@ -364,6 +367,9 @@ files:
364
367
  - spec/support/fixtures/vcr_cassettes/user_management/verify_email/invalid_code.yml
365
368
  - spec/support/fixtures/vcr_cassettes/user_management/verify_email/invalid_magic_auth_challenge.yml
366
369
  - spec/support/fixtures/vcr_cassettes/user_management/verify_email/valid.yml
370
+ - spec/support/fixtures/vcr_cassettes/widgets/get_token.yml
371
+ - spec/support/fixtures/vcr_cassettes/widgets/get_token_invalid_organization_id.yml
372
+ - spec/support/fixtures/vcr_cassettes/widgets/get_token_invalid_user_id.yml
367
373
  - spec/support/profile.txt
368
374
  - spec/support/shared_examples/client.rb
369
375
  - spec/support/webhook_payload.txt
@@ -407,6 +413,7 @@ test_files:
407
413
  - spec/lib/workos/sso_spec.rb
408
414
  - spec/lib/workos/user_management_spec.rb
409
415
  - spec/lib/workos/webhooks_spec.rb
416
+ - spec/lib/workos/widgets_spec.rb
410
417
  - spec/spec_helper.rb
411
418
  - spec/support/fixtures/vcr_cassettes/audit_logs/create_event.yml
412
419
  - spec/support/fixtures/vcr_cassettes/audit_logs/create_event_custom_idempotency_key.yml
@@ -577,6 +584,9 @@ test_files:
577
584
  - spec/support/fixtures/vcr_cassettes/user_management/verify_email/invalid_code.yml
578
585
  - spec/support/fixtures/vcr_cassettes/user_management/verify_email/invalid_magic_auth_challenge.yml
579
586
  - spec/support/fixtures/vcr_cassettes/user_management/verify_email/valid.yml
587
+ - spec/support/fixtures/vcr_cassettes/widgets/get_token.yml
588
+ - spec/support/fixtures/vcr_cassettes/widgets/get_token_invalid_organization_id.yml
589
+ - spec/support/fixtures/vcr_cassettes/widgets/get_token_invalid_user_id.yml
580
590
  - spec/support/profile.txt
581
591
  - spec/support/shared_examples/client.rb
582
592
  - spec/support/webhook_payload.txt