@@ -527,24 +527,9 @@ def __init__(
527
527
self ._try_magic ()
528
528
529
529
assert isinstance (self ._options ["headers" ], dict ) # for mypy benefit
530
- self ._session : ResilientSession # for mypy benefit
531
- if oauth :
532
- self ._create_oauth_session (oauth , timeout )
533
- elif basic_auth :
534
- self ._create_http_basic_session (* basic_auth , timeout = timeout )
535
- elif jwt :
536
- self ._create_jwt_session (jwt , timeout )
537
- elif token_auth :
538
- self ._create_token_session (token_auth , timeout )
539
- elif kerberos :
540
- self ._create_kerberos_session (timeout , kerberos_options = kerberos_options )
541
- elif auth :
542
- self ._create_cookie_auth (auth , timeout )
543
- # always log in for cookie based auth, as we need a first request to be logged in
544
- validate = True
545
- else :
546
- self ._session = ResilientSession (timeout = timeout )
547
530
531
+ # Create Session object and update with config options first
532
+ self ._session = ResilientSession (timeout = timeout )
548
533
# Add the client authentication certificate to the request if configured
549
534
self ._add_client_cert_to_session ()
550
535
# Add the SSL Cert to the request if configured
@@ -560,6 +545,23 @@ def __init__(
560
545
if proxies :
561
546
self ._session .proxies = proxies
562
547
548
+ # Setup the Auth last,
549
+ # so that if any handlers take a copy of the session obj it will be ready
550
+ if oauth :
551
+ self ._create_oauth_session (oauth )
552
+ elif basic_auth :
553
+ self ._create_http_basic_session (* basic_auth )
554
+ elif jwt :
555
+ self ._create_jwt_session (jwt )
556
+ elif token_auth :
557
+ self ._create_token_session (token_auth )
558
+ elif kerberos :
559
+ self ._create_kerberos_session (kerberos_options = kerberos_options )
560
+ elif auth :
561
+ self ._create_cookie_auth (auth )
562
+ # always log in for cookie based auth, as we need a first request to be logged in
563
+ validate = True
564
+
563
565
self .auth = auth
564
566
if validate :
565
567
# This will raise an Exception if you are not allowed to login.
@@ -619,17 +621,12 @@ def _is_cloud(self) -> bool:
619
621
"""Return whether we are on a Cloud based Jira instance."""
620
622
return self .deploymentType in ("Cloud" ,)
621
623
622
- def _create_cookie_auth (
623
- self ,
624
- auth : tuple [str , str ],
625
- timeout : None | float | tuple [float , float ] | tuple [float , None ] | None = None ,
626
- ):
624
+ def _create_cookie_auth (self , auth : tuple [str , str ]):
627
625
warnings .warn (
628
626
"Use OAuth or Token based authentication "
629
627
+ "instead of Cookie based Authentication." ,
630
628
DeprecationWarning ,
631
629
)
632
- self ._session = ResilientSession (timeout = timeout )
633
630
self ._session .auth = JiraCookieAuth (
634
631
session = self ._session ,
635
632
session_api_url = "{server}{auth_url}" .format (** self ._options ),
@@ -3678,28 +3675,19 @@ def kill_websudo(self) -> Response | None:
3678
3675
return None
3679
3676
3680
3677
# Utilities
3681
- def _create_http_basic_session (
3682
- self ,
3683
- username : str ,
3684
- password : str ,
3685
- timeout : None | float | tuple [float , float ] | tuple [float , None ] | None = None ,
3686
- ):
3678
+ def _create_http_basic_session (self , username : str , password : str ):
3687
3679
"""Creates a basic http session.
3688
3680
3689
3681
Args:
3690
3682
username (str): Username for the session
3691
3683
password (str): Password for the username
3692
- timeout (Optional[int]): If set determines the connection/read timeout delay for the Session.
3693
3684
3694
3685
Returns:
3695
3686
ResilientSession
3696
3687
"""
3697
- self ._session = ResilientSession (timeout = timeout )
3698
3688
self ._session .auth = (username , password )
3699
3689
3700
- def _create_oauth_session (
3701
- self , oauth , timeout : float | int | tuple [float , float ] | None
3702
- ):
3690
+ def _create_oauth_session (self , oauth : dict [str , Any ]):
3703
3691
from oauthlib .oauth1 import SIGNATURE_HMAC_SHA1
3704
3692
from requests_oauthlib import OAuth1
3705
3693
@@ -3710,13 +3698,11 @@ def _create_oauth_session(
3710
3698
resource_owner_key = oauth ["access_token" ],
3711
3699
resource_owner_secret = oauth ["access_token_secret" ],
3712
3700
)
3713
- self ._session = ResilientSession (timeout )
3714
3701
self ._session .auth = oauth_instance
3715
3702
3716
3703
def _create_kerberos_session (
3717
3704
self ,
3718
- timeout : None | float | tuple [float , float ] | tuple [float , None ] | None ,
3719
- kerberos_options = None ,
3705
+ kerberos_options : dict [str , Any ] = None ,
3720
3706
):
3721
3707
if kerberos_options is None :
3722
3708
kerberos_options = {}
@@ -3733,7 +3719,6 @@ def _create_kerberos_session(
3733
3719
% kerberos_options ["mutual_authentication" ]
3734
3720
)
3735
3721
3736
- self ._session = ResilientSession (timeout = timeout )
3737
3722
self ._session .auth = HTTPKerberosAuth (
3738
3723
mutual_authentication = mutual_authentication
3739
3724
)
@@ -3769,9 +3754,7 @@ def _timestamp(dt: datetime.timedelta = None):
3769
3754
t += dt
3770
3755
return calendar .timegm (t .timetuple ())
3771
3756
3772
- def _create_jwt_session (
3773
- self , jwt , timeout : float | int | tuple [float , float ] | None
3774
- ):
3757
+ def _create_jwt_session (self , jwt : dict [str , Any ]):
3775
3758
try :
3776
3759
jwt_auth = JWTAuth (jwt ["secret" ], alg = "HS256" )
3777
3760
except NameError as e :
@@ -3786,19 +3769,13 @@ def _create_jwt_session(
3786
3769
jwt_auth .add_field ("qsh" , QshGenerator (self ._options ["context_path" ]))
3787
3770
for f in jwt ["payload" ].items ():
3788
3771
jwt_auth .add_field (f [0 ], f [1 ])
3789
- self ._session = ResilientSession (timeout = timeout )
3790
3772
self ._session .auth = jwt_auth
3791
3773
3792
- def _create_token_session (
3793
- self ,
3794
- token_auth : str ,
3795
- timeout : None | float | tuple [float , float ] | tuple [float , None ] | None = None ,
3796
- ):
3774
+ def _create_token_session (self , token_auth : str ):
3797
3775
"""Creates token-based session.
3798
3776
3799
3777
Header structure: "authorization": "Bearer <token_auth>".
3800
3778
"""
3801
- self ._session = ResilientSession (timeout = timeout )
3802
3779
self ._session .auth = TokenAuth (token_auth )
3803
3780
3804
3781
def _set_avatar (self , params , url , avatar ):
0 commit comments