11# coding: utf-8
22
3- # © Copyright IBM Corporation 2020, 2022 .
3+ # © Copyright IBM Corporation 2020, 2025 .
44#
55# Licensed under the Apache License, Version 2.0 (the "License");
66# you may not use this file except in compliance with the License.
1616"""
1717Module for handling session authentication
1818"""
19- from requests import Request
19+ from requests import Request , Session
2020
2121from ibm_cloud_sdk_core .authenticators import Authenticator
2222from .couchdb_session_token_manager import CouchDbSessionTokenManager
@@ -46,20 +46,21 @@ def __init__(self,
4646 if not isinstance (disable_ssl_verification , bool ):
4747 raise TypeError ('disable_ssl_verification must be a bool' )
4848
49- self .jar = None
50-
5149 self .token_manager = CouchDbSessionTokenManager (
5250 username ,
5351 password ,
5452 disable_ssl_verification = disable_ssl_verification
5553 )
5654 self .validate ()
5755
58- def set_jar (self , jar ) :
59- """Sets the cookie jar for the authenticator.
56+ def set_http_client (self , http_client : Session ) -> None :
57+ """Sets base serivice's http client for the authenticator.
6058 This is an internal method called by BaseService. Not to be called directly.
6159 """
62- self .jar = jar
60+ if isinstance (http_client , Session ):
61+ self .token_manager .http_client = http_client
62+ else :
63+ raise TypeError ("http_client parameter must be a requests.sessions.Session" )
6364
6465 def validate (self ):
6566 """Validates the username, and password for session token requests.
@@ -82,11 +83,7 @@ def authenticate(self, req: Request):
8283 Args:
8384 req: Ignored. BaseService uses the cookie jar for every request
8485 """
85- jar = self .token_manager .get_token ()
86- # Requests seem to save cookies only for Sessions. BaseService is
87- # hard-coded to work with "regular" requests requests so updating
88- # the jar manually is necessary
89- self .jar .update (jar )
86+ self .token_manager .get_token ()
9087
9188 def authentication_type (self ) -> str :
9289 """Returns this authenticator's type ('COUCHDB_SESSION')."""
0 commit comments