Skip to content

Support Basic authentication #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions elmclient/httpops.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,35 @@ def _login(self, auth_url):
auth_url_response = self._session.get(auth_url) # Load up them cookies!
self.log_redirection_history( auth_url_response, intent="Login",donotlogbody=True )

if auth_url_response.headers.get('X-com-ibm-team-repository-web-auth-msg') != 'authrequired':
login_url = auth_url_response.url # Take the redirected URL and login action URL

# Check for Basic auth
www_auth = auth_url_response.headers.get('www-authenticate', '').lower()
if "basic" in www_auth:
logger.debug("Basic Auth required by the server")
# Build basic auth header
username, password = self.get_user_password(login_url)
credentials = f"{username}:{password}"
import base64
token = base64.b64encode(credentials.encode('utf-8')).decode('ascii')
headers = {
'Authorization': f"Basic {token}"
}
logger.debug("Sending Basic Auth header")

# Retry with basic auth
auth_response = self._session.get(auth_url, headers=headers)
if auth_response.status_code == 200:
logger.debug("Basic Auth is successful")
else:
logger.error(f"Basic Auth failed: {auth_response.status_code}")
raise Exception("Login failed with Basic Auth")
return None # auth completed

elif auth_url_response.headers.get('X-com-ibm-team-repository-web-auth-msg') != 'authrequired':
logger.trace("headers show auth not required")
return None # no more auth required
login_url = auth_url_response.url # Take the redirected URL and login action URL

self._authorize(login_url)

logger.trace("authorized")
Expand Down