@@ -278,9 +278,20 @@ def delete_user(id:)
278278 # @param [String] client_id The WorkOS client ID for the environment
279279 # @param [String] ip_address The IP address of the request from the user who is attempting to authenticate.
280280 # @param [String] user_agent The user agent of the request from the user who is attempting to authenticate.
281+ # @param [Hash] session An optional hash that determines whether the session should be sealed and
282+ # the optional cookie password.
281283 #
282284 # @return WorkOS::AuthenticationResponse
283- def authenticate_with_password ( email :, password :, client_id :, ip_address : nil , user_agent : nil )
285+ def authenticate_with_password (
286+ email :,
287+ password :,
288+ client_id :,
289+ ip_address : nil ,
290+ user_agent : nil ,
291+ session : nil
292+ )
293+ validate_session ( session )
294+
284295 response = execute_request (
285296 request : post_request (
286297 path : '/user_management/authenticate' ,
@@ -296,7 +307,7 @@ def authenticate_with_password(email:, password:, client_id:, ip_address: nil, u
296307 ) ,
297308 )
298309
299- WorkOS ::AuthenticationResponse . new ( response . body )
310+ WorkOS ::AuthenticationResponse . new ( response . body , session )
300311 end
301312
302313 # Authenticate a user using OAuth or an organization's SSO connection.
@@ -317,9 +328,7 @@ def authenticate_with_code(
317328 user_agent : nil ,
318329 session : nil
319330 )
320- if session && ( session [ :seal_session ] == true ) && session [ :cookie_password ] . nil?
321- raise ArgumentError , 'cookie_password is required when sealing session'
322- end
331+ validate_session ( session )
323332
324333 response = execute_request (
325334 request : post_request (
@@ -357,9 +366,7 @@ def authenticate_with_refresh_token(
357366 user_agent : nil ,
358367 session : nil
359368 )
360- if session && ( session [ :seal_session ] == true ) && session [ :cookie_password ] . nil?
361- raise ArgumentError , 'cookie_password is required when sealing session'
362- end
369+ validate_session ( session )
363370
364371 response = execute_request (
365372 request : post_request (
@@ -388,16 +395,22 @@ def authenticate_with_refresh_token(
388395 # @param [String] link_authorization_code Used to link an OAuth profile to an existing user,
389396 # after having completed a Magic Code challenge.
390397 # @param [String] user_agent The user agent of the request from the user who is attempting to authenticate.
398+ # @param [Hash] session An optional hash that determines whether the session should be sealed and
399+ # the optional cookie password.
391400 #
392401 # @return WorkOS::AuthenticationResponse
402+ # rubocop:disable Metrics/ParameterLists
393403 def authenticate_with_magic_auth (
394404 code :,
395405 email :,
396406 client_id :,
397407 ip_address : nil ,
398408 user_agent : nil ,
399- link_authorization_code : nil
409+ link_authorization_code : nil ,
410+ session : nil
400411 )
412+ validate_session ( session )
413+
401414 response = execute_request (
402415 request : post_request (
403416 path : '/user_management/authenticate' ,
@@ -414,8 +427,9 @@ def authenticate_with_magic_auth(
414427 ) ,
415428 )
416429
417- WorkOS ::AuthenticationResponse . new ( response . body )
430+ WorkOS ::AuthenticationResponse . new ( response . body , session )
418431 end
432+ # rubocop:enable Metrics/ParameterLists
419433
420434 # Authenticate a user into an organization they are a member of.
421435 #
@@ -424,15 +438,20 @@ def authenticate_with_magic_auth(
424438 # @param [String] pending_authentication_token The pending authentication token
425439 # @param [String] ip_address The IP address of the request from the user who is attempting to authenticate.
426440 # @param [String] user_agent The user agent of the request from the user who is attempting to authenticate.
441+ # @param [Hash] session An optional hash that determines whether the session should be sealed and
442+ # the optional cookie password.
427443 #
428444 # @return WorkOS::AuthenticationResponse
429445 def authenticate_with_organization_selection (
430446 client_id :,
431447 organization_id :,
432448 pending_authentication_token :,
433449 ip_address : nil ,
434- user_agent : nil
450+ user_agent : nil ,
451+ session : nil
435452 )
453+ validate_session ( session )
454+
436455 response = execute_request (
437456 request : post_request (
438457 path : '/user_management/authenticate' ,
@@ -448,7 +467,7 @@ def authenticate_with_organization_selection(
448467 ) ,
449468 )
450469
451- WorkOS ::AuthenticationResponse . new ( response . body )
470+ WorkOS ::AuthenticationResponse . new ( response . body , session )
452471 end
453472
454473 # Authenticate a user using TOTP.
@@ -461,16 +480,22 @@ def authenticate_with_organization_selection(
461480 # authentication request.
462481 # @param [String] ip_address The IP address of the request from the user who is attempting to authenticate.
463482 # @param [String] user_agent The user agent of the request from the user who is attempting to authenticate.
483+ # @param [Hash] session An optional hash that determines whether the session should be sealed and
484+ # the optional cookie password.
464485 #
465486 # @return WorkOS::AuthenticationResponse
487+ # rubocop:disable Metrics/ParameterLists
466488 def authenticate_with_totp (
467489 code :,
468490 client_id :,
469491 pending_authentication_token :,
470492 authentication_challenge_id :,
471493 ip_address : nil ,
472- user_agent : nil
494+ user_agent : nil ,
495+ session : nil
473496 )
497+ validate_session ( session )
498+
474499 response = execute_request (
475500 request : post_request (
476501 path : '/user_management/authenticate' ,
@@ -487,8 +512,9 @@ def authenticate_with_totp(
487512 ) ,
488513 )
489514
490- WorkOS ::AuthenticationResponse . new ( response . body )
515+ WorkOS ::AuthenticationResponse . new ( response . body , session )
491516 end
517+ # rubocop:enable Metrics/ParameterLists
492518
493519 # Authenticate a user using Email Verification Code.
494520 #
@@ -498,15 +524,20 @@ def authenticate_with_totp(
498524 # authentication attempt due to an unverified email address.
499525 # @param [String] ip_address The IP address of the request from the user who is attempting to authenticate.
500526 # @param [String] user_agent The user agent of the request from the user who is attempting to authenticate.
527+ # @param [Hash] session An optional hash that determines whether the session should be sealed and
528+ # the optional cookie password.
501529 #
502530 # @return WorkOS::AuthenticationResponse
503531 def authenticate_with_email_verification (
504532 code :,
505533 client_id :,
506534 pending_authentication_token :,
507535 ip_address : nil ,
508- user_agent : nil
536+ user_agent : nil ,
537+ session : nil
509538 )
539+ validate_session ( session )
540+
510541 response = execute_request (
511542 request : post_request (
512543 path : '/user_management/authenticate' ,
@@ -522,7 +553,7 @@ def authenticate_with_email_verification(
522553 ) ,
523554 )
524555
525- WorkOS ::AuthenticationResponse . new ( response . body )
556+ WorkOS ::AuthenticationResponse . new ( response . body , session )
526557 end
527558
528559 # Get the logout URL for a session
@@ -1082,6 +1113,12 @@ def revoke_invitation(id:)
10821113
10831114 private
10841115
1116+ def validate_session ( session )
1117+ return unless session && ( session [ :seal_session ] == true ) && session [ :cookie_password ] . nil?
1118+
1119+ raise ArgumentError , 'cookie_password is required when sealing session'
1120+ end
1121+
10851122 def validate_authorization_url_arguments (
10861123 provider :,
10871124 connection_id :,
0 commit comments