workos 5.10.0 → 5.11.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 +2 -2
- data/lib/workos/session.rb +3 -4
- data/lib/workos/user_management.rb +6 -2
- data/lib/workos/version.rb +1 -1
- data/spec/lib/workos/session_spec.rb +30 -12
- data/spec/lib/workos/user_management_spec.rb +21 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3b8df2a135ab2c2493c5d18c0435f81facd859e396671de49f5407943abfb0b
|
4
|
+
data.tar.gz: 1aa8b210fffda9deece1478ef33d0cc85ac014e8c03bc308d6959ca6984563e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ada12739dd063caf865f32aab5db4376177b6642ada12cd7d5457cdd9a000f5cd419ca39964b3f24cc73801579c4bf8e1d8832a7cc92b2aaaf09b3fb4edf9fb
|
7
|
+
data.tar.gz: 395e87fa94cf398df6febdbbc65616613ad175a8ab624c40fb991509428481178e03ebba613913fd4d050ea62b05f21feeae05478c1efcb86004e127da893af3
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
workos (5.
|
4
|
+
workos (5.11.0)
|
5
5
|
encryptor (~> 3.0)
|
6
6
|
jwt (~> 2.8)
|
7
7
|
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
diff-lcs (1.5.1)
|
20
20
|
encryptor (3.0.0)
|
21
21
|
hashdiff (1.1.0)
|
22
|
-
jwt (2.
|
22
|
+
jwt (2.10.1)
|
23
23
|
base64
|
24
24
|
parallel (1.24.0)
|
25
25
|
parser (3.3.0.5)
|
data/lib/workos/session.rb
CHANGED
@@ -101,18 +101,17 @@ module WorkOS
|
|
101
101
|
# rubocop:enable Metrics/PerceivedComplexity
|
102
102
|
|
103
103
|
# Returns a URL to redirect the user to for logging out
|
104
|
+
# @param return_to [String] The URL to redirect the user to after logging out
|
104
105
|
# @return [String] The URL to redirect the user to for logging out
|
105
|
-
|
106
|
-
def get_logout_url
|
106
|
+
def get_logout_url(return_to: nil)
|
107
107
|
auth_response = authenticate
|
108
108
|
|
109
109
|
unless auth_response[:authenticated]
|
110
110
|
raise "Failed to extract session ID for logout URL: #{auth_response[:reason]}"
|
111
111
|
end
|
112
112
|
|
113
|
-
@user_management.get_logout_url(session_id: auth_response[:session_id])
|
113
|
+
@user_management.get_logout_url(session_id: auth_response[:session_id], return_to: return_to)
|
114
114
|
end
|
115
|
-
# rubocop:enable Naming/AccessorMethodName
|
116
115
|
|
117
116
|
# Encrypts and seals data using AES-256-GCM
|
118
117
|
# @param data [Hash] The data to seal
|
@@ -530,13 +530,17 @@ module WorkOS
|
|
530
530
|
#
|
531
531
|
# @param [String] session_id The session ID can be found in the `sid`
|
532
532
|
# claim of the access token
|
533
|
+
# @param [String] return_to The URL to redirect the user to after logging out
|
533
534
|
#
|
534
535
|
# @return String
|
535
|
-
def get_logout_url(session_id:)
|
536
|
+
def get_logout_url(session_id:, return_to: nil)
|
537
|
+
params = { session_id: session_id }
|
538
|
+
params[:return_to] = return_to if return_to
|
539
|
+
|
536
540
|
URI::HTTPS.build(
|
537
541
|
host: WorkOS.config.api_hostname,
|
538
542
|
path: '/user_management/sessions/logout',
|
539
|
-
query:
|
543
|
+
query: URI.encode_www_form(params),
|
540
544
|
).to_s
|
541
545
|
end
|
542
546
|
|
data/lib/workos/version.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe WorkOS::Session do
|
4
|
-
let(:user_management) { instance_double('UserManagement') }
|
5
4
|
let(:client_id) { 'test_client_id' }
|
6
5
|
let(:cookie_password) { 'test_very_long_cookie_password__' }
|
7
6
|
let(:session_data) { 'test_session_data' }
|
@@ -10,11 +9,16 @@ describe WorkOS::Session do
|
|
10
9
|
let(:jwk) { JWT::JWK.new(OpenSSL::PKey::RSA.new(2048), { kid: 'sso_oidc_key_pair_123', use: 'sig', alg: 'RS256' }) }
|
11
10
|
|
12
11
|
before do
|
13
|
-
allow(user_management).to receive(:get_jwks_url).with(client_id).and_return(jwks_url)
|
14
12
|
allow(Net::HTTP).to receive(:get).and_return(jwks_hash)
|
15
13
|
end
|
16
14
|
|
17
15
|
describe 'initialize' do
|
16
|
+
let(:user_management) { instance_double('UserManagement') }
|
17
|
+
|
18
|
+
before do
|
19
|
+
allow(user_management).to receive(:get_jwks_url).with(client_id).and_return(jwks_url)
|
20
|
+
end
|
21
|
+
|
18
22
|
it 'raises an error if cookie_password is nil or empty' do
|
19
23
|
expect do
|
20
24
|
WorkOS::Session.new(
|
@@ -52,6 +56,7 @@ describe WorkOS::Session do
|
|
52
56
|
end
|
53
57
|
|
54
58
|
describe '.authenticate' do
|
59
|
+
let(:user_management) { instance_double('UserManagement') }
|
55
60
|
let(:valid_access_token) do
|
56
61
|
payload = {
|
57
62
|
sid: 'session_id',
|
@@ -71,6 +76,10 @@ describe WorkOS::Session do
|
|
71
76
|
}, cookie_password,)
|
72
77
|
end
|
73
78
|
|
79
|
+
before do
|
80
|
+
allow(user_management).to receive(:get_jwks_url).with(client_id).and_return(jwks_url)
|
81
|
+
end
|
82
|
+
|
74
83
|
it 'returns NO_SESSION_COOKIE_PROVIDED if session_data is nil' do
|
75
84
|
session = WorkOS::Session.new(
|
76
85
|
user_management: user_management,
|
@@ -135,11 +144,13 @@ end
|
|
135
144
|
end
|
136
145
|
|
137
146
|
describe '.refresh' do
|
147
|
+
let(:user_management) { instance_double('UserManagement') }
|
138
148
|
let(:refresh_token) { 'test_refresh_token' }
|
139
149
|
let(:session_data) { WorkOS::Session.seal_data({ refresh_token: refresh_token, user: 'user' }, cookie_password) }
|
140
150
|
let(:auth_response) { double('AuthResponse', sealed_session: 'new_sealed_session') }
|
141
151
|
|
142
152
|
before do
|
153
|
+
allow(user_management).to receive(:get_jwks_url).with(client_id).and_return(jwks_url)
|
143
154
|
allow(user_management).to receive(:authenticate_with_refresh_token).and_return(auth_response)
|
144
155
|
end
|
145
156
|
|
@@ -173,26 +184,33 @@ end
|
|
173
184
|
|
174
185
|
describe '.get_logout_url' do
|
175
186
|
let(:session) do
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
187
|
+
WorkOS::Session.new(
|
188
|
+
user_management: WorkOS::UserManagement,
|
189
|
+
client_id: client_id,
|
190
|
+
session_data: session_data,
|
191
|
+
cookie_password: cookie_password,
|
192
|
+
)
|
193
|
+
end
|
183
194
|
|
184
195
|
context 'when authentication is successful' do
|
185
196
|
before do
|
186
197
|
allow(session).to receive(:authenticate).and_return({
|
187
198
|
authenticated: true,
|
188
|
-
session_id: '
|
199
|
+
session_id: 'session_123abc',
|
189
200
|
reason: nil,
|
190
201
|
})
|
191
|
-
allow(user_management).to receive(:get_logout_url).with(session_id: 'session_id').and_return('https://example.com/logout')
|
192
202
|
end
|
193
203
|
|
194
204
|
it 'returns the logout URL' do
|
195
|
-
expect(session.get_logout_url).to eq('https://
|
205
|
+
expect(session.get_logout_url).to eq('https://api.workos.com/user_management/sessions/logout?session_id=session_123abc')
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'when given a return_to URL' do
|
209
|
+
it 'returns the logout URL with the return_to parameter' do
|
210
|
+
expect(session.get_logout_url(return_to: 'https://example.com/signed-out')).to eq(
|
211
|
+
'https://api.workos.com/user_management/sessions/logout?session_id=session_123abc&return_to=https%3A%2F%2Fexample.com%2Fsigned-out',
|
212
|
+
)
|
213
|
+
end
|
196
214
|
end
|
197
215
|
end
|
198
216
|
|
@@ -1441,4 +1441,25 @@ describe WorkOS::UserManagement do
|
|
1441
1441
|
end
|
1442
1442
|
end
|
1443
1443
|
end
|
1444
|
+
|
1445
|
+
describe '.get_logout_url' do
|
1446
|
+
it 'returns a logout url for the given session ID' do
|
1447
|
+
result = described_class.get_logout_url(
|
1448
|
+
session_id: 'session_01HRX85ATNADY1GQ053AHRFFN6',
|
1449
|
+
)
|
1450
|
+
|
1451
|
+
expect(result).to eq 'https://api.workos.com/user_management/sessions/logout?session_id=session_01HRX85ATNADY1GQ053AHRFFN6'
|
1452
|
+
end
|
1453
|
+
|
1454
|
+
context 'when a `return_to` is given' do
|
1455
|
+
it 'returns a logout url with the `return_to` query parameter' do
|
1456
|
+
result = described_class.get_logout_url(
|
1457
|
+
session_id: 'session_01HRX85ATNADY1GQ053AHRFFN6',
|
1458
|
+
return_to: 'https://example.com/signed-out',
|
1459
|
+
)
|
1460
|
+
|
1461
|
+
expect(result).to eq 'https://api.workos.com/user_management/sessions/logout?session_id=session_01HRX85ATNADY1GQ053AHRFFN6&return_to=https%3A%2F%2Fexample.com%2Fsigned-out'
|
1462
|
+
end
|
1463
|
+
end
|
1464
|
+
end
|
1444
1465
|
end
|
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.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WorkOS
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: encryptor
|