Skip to content

Commit 9239c9e

Browse files
committed
Add invitation_token parameter to authentication methods
1 parent b8f7796 commit 9239c9e

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

lib/workos/user_management.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def delete_user(id:)
298298
# @param [String] client_id The WorkOS client ID for the environment
299299
# @param [String] ip_address The IP address of the request from the user who is attempting to authenticate.
300300
# @param [String] user_agent The user agent of the request from the user who is attempting to authenticate.
301+
# @param [String] invitation_token The token of an Invitation, if required.
301302
# @param [Hash] session An optional hash that determines whether the session should be sealed and
302303
# the optional cookie password.
303304
#
@@ -308,6 +309,7 @@ def authenticate_with_password(
308309
client_id:,
309310
ip_address: nil,
310311
user_agent: nil,
312+
invitation_token: nil,
311313
session: nil
312314
)
313315
validate_session(session)
@@ -322,6 +324,7 @@ def authenticate_with_password(
322324
password: password,
323325
ip_address: ip_address,
324326
user_agent: user_agent,
327+
invitation_token: invitation_token,
325328
grant_type: 'password',
326329
},
327330
),
@@ -337,6 +340,7 @@ def authenticate_with_password(
337340
# @param [String] client_id The WorkOS client ID for the environment
338341
# @param [String] ip_address The IP address of the request from the user who is attempting to authenticate.
339342
# @param [String] user_agent The user agent of the request from the user who is attempting to authenticate.
343+
# @param [String] invitation_token The token of an Invitation, if required.
340344
# @param [Hash] session An optional hash that determines whether the session should be sealed and
341345
# the optional cookie password.
342346
#
@@ -346,6 +350,7 @@ def authenticate_with_code(
346350
client_id:,
347351
ip_address: nil,
348352
user_agent: nil,
353+
invitation_token: nil,
349354
session: nil
350355
)
351356
validate_session(session)
@@ -359,6 +364,7 @@ def authenticate_with_code(
359364
client_secret: WorkOS.config.key!,
360365
ip_address: ip_address,
361366
user_agent: user_agent,
367+
invitation_token: invitation_token,
362368
grant_type: 'authorization_code',
363369
},
364370
),
@@ -415,6 +421,7 @@ def authenticate_with_refresh_token(
415421
# @param [String] link_authorization_code Used to link an OAuth profile to an existing user,
416422
# after having completed a Magic Code challenge.
417423
# @param [String] user_agent The user agent of the request from the user who is attempting to authenticate.
424+
# @param [String] invitation_token The token of an Invitation, if required.
418425
# @param [Hash] session An optional hash that determines whether the session should be sealed and
419426
# the optional cookie password.
420427
#
@@ -427,6 +434,7 @@ def authenticate_with_magic_auth(
427434
ip_address: nil,
428435
user_agent: nil,
429436
link_authorization_code: nil,
437+
invitation_token: nil,
430438
session: nil
431439
)
432440
validate_session(session)
@@ -443,6 +451,7 @@ def authenticate_with_magic_auth(
443451
user_agent: user_agent,
444452
grant_type: 'urn:workos:oauth:grant-type:magic-auth:code',
445453
link_authorization_code: link_authorization_code,
454+
invitation_token: invitation_token,
446455
},
447456
),
448457
)

spec/lib/workos/user_management_spec.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,28 @@
588588
end
589589
end
590590
end
591+
592+
context 'with an invitation_token' do
593+
it 'includes invitation_token in the request body' do
594+
expect(described_class).to receive(:post_request) do |options|
595+
body = options[:body]
596+
expect(body[:invitation_token]).to eq('invitation_token_123')
597+
598+
double('request')
599+
end.and_return(double('request'))
600+
601+
expect(described_class).to receive(:execute_request).and_return(
602+
double('response', body: '{"user": {"id": "user_123"}, "access_token": "token", "refresh_token": "refresh"}'),
603+
)
604+
605+
described_class.authenticate_with_password(
606+
email: 'test@workos.app',
607+
password: 'password123',
608+
client_id: 'client_123',
609+
invitation_token: 'invitation_token_123',
610+
)
611+
end
612+
end
591613
end
592614

593615
describe '.authenticate_with_code' do
@@ -671,6 +693,27 @@
671693
end
672694
end
673695
end
696+
697+
context 'with an invitation_token' do
698+
it 'includes invitation_token in the request body' do
699+
expect(described_class).to receive(:post_request) do |options|
700+
body = options[:body]
701+
expect(body[:invitation_token]).to eq('invitation_token_123')
702+
703+
double('request')
704+
end.and_return(double('request'))
705+
706+
expect(described_class).to receive(:execute_request).and_return(
707+
double('response', body: '{"user": {"id": "user_123"}, "access_token": "token", "refresh_token": "refresh"}'),
708+
)
709+
710+
described_class.authenticate_with_code(
711+
code: '01H93ZZHA0JBHFJH9RR11S83YN',
712+
client_id: 'client_123',
713+
invitation_token: 'invitation_token_123',
714+
)
715+
end
716+
end
674717
end
675718

676719
describe '.authenticate_with_refresh_token' do
@@ -735,6 +778,28 @@
735778
end
736779
end
737780
end
781+
782+
context 'with an invitation_token' do
783+
it 'includes invitation_token in the request body' do
784+
expect(described_class).to receive(:post_request) do |options|
785+
body = options[:body]
786+
expect(body[:invitation_token]).to eq('invitation_token_123')
787+
788+
double('request')
789+
end.and_return(double('request'))
790+
791+
expect(described_class).to receive(:execute_request).and_return(
792+
double('response', body: '{"user": {"id": "user_123"}, "access_token": "token", "refresh_token": "refresh"}'),
793+
)
794+
795+
described_class.authenticate_with_magic_auth(
796+
code: '452079',
797+
client_id: 'client_123',
798+
email: 'test@workos.com',
799+
invitation_token: 'invitation_token_123',
800+
)
801+
end
802+
end
738803
end
739804

740805
describe '.authenticate_with_organization_selection' do

0 commit comments

Comments
 (0)