@@ -735,10 +735,35 @@ def _login(self, auth_url):
735
735
auth_url_response = self ._session .get (auth_url ) # Load up them cookies!
736
736
self .log_redirection_history ( auth_url_response , intent = "Login" ,donotlogbody = True )
737
737
738
- if auth_url_response .headers .get ('X-com-ibm-team-repository-web-auth-msg' ) != 'authrequired' :
738
+ login_url = auth_url_response .url # Take the redirected URL and login action URL
739
+
740
+ # Check for Basic auth
741
+ www_auth = auth_url_response .headers .get ('www-authenticate' , '' ).lower ()
742
+ if "basic" in www_auth :
743
+ logger .debug ("Basic Auth required by the server" )
744
+ # Build basic auth header
745
+ username , password = self .get_user_password (login_url )
746
+ credentials = f"{ username } :{ password } "
747
+ import base64
748
+ token = base64 .b64encode (credentials .encode ('utf-8' )).decode ('ascii' )
749
+ headers = {
750
+ 'Authorization' : f"Basic { token } "
751
+ }
752
+ logger .debug ("Sending Basic Auth header" )
753
+
754
+ # Retry with basic auth
755
+ auth_response = self ._session .get (auth_url , headers = headers )
756
+ if auth_response .status_code == 200 :
757
+ logger .debug ("Basic Auth is successful" )
758
+ else :
759
+ logger .error (f"Basic Auth failed: { auth_response .status_code } " )
760
+ raise Exception ("Login failed with Basic Auth" )
761
+ return None # auth completed
762
+
763
+ elif auth_url_response .headers .get ('X-com-ibm-team-repository-web-auth-msg' ) != 'authrequired' :
739
764
logger .trace ("headers show auth not required" )
740
765
return None # no more auth required
741
- login_url = auth_url_response . url # Take the redirected URL and login action URL
766
+
742
767
self ._authorize (login_url )
743
768
744
769
logger .trace ("authorized" )
0 commit comments