Skip to content
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

Added code to force authentication on first request instead of authentication-challenge #238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

enothen
Copy link

@enothen enothen commented May 31, 2023

Added "forceauth" parameter to address issue #175.

Current default behavior is kept:

>>> h = httplib2.Http(".cache")
>>> h.add_credentials(user, password)
>>> headersDict={'Content-Type':'application/json','accept':'application/json'}
>>> response, content = h.request(url, 'GET', headers=headersDict)
>>> 
>>> response.status
401
>>> 

The webserver in the example above does not return a "www-authenticate" header, and so authentication is not tried (even though credentials are provided and a 401 is received in the first attempt):

>>> response
{'date': 'Wed, 31 May 2023 12:29:44 GMT', 'server': 'Apache', 'content-type': 'application/json; charset=utf-8', 'apipie-checksum': '5346b3362dcb7d38bd1dd226bc763427f7fe8200', 'cache-control': 'no-cache', 'x-request-id': 'e27cfd25-00ad-466a-b03f-c1a849001697', 'x-runtime': '0.026089', 'strict-transport-security': 'max-age=631139040; includeSubdomains', 'x-frame-options': 'sameorigin', 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'x-download-options': 'noopen', 'x-permitted-cross-domain-policies': 'none', 'content-security-policy': "default-src 'self'; child-src 'self'; connect-src 'self' ws: wss:; img-src 'self' data:; script-src 'unsafe-eval' 'unsafe-inline' 'self'; style-src 'unsafe-inline' 'self'", 'via': '1.1 satellite.keller.lab', 'transfer-encoding': 'chunked', 'status': '401'}

And from the webserver side:

192.168.122.149 - - [31/May/2023:12:29:44 +0000] "GET /api/hosts HTTP/1.1" 401 58 "-" "Python-httplib2/0.13.1 (gzip)"

Forcing auth allows successful login on the first try:

>>> h2 = httplib2.Http(forceauth="basic")
>>> h2.add_credentials(user, password)
>>> response, content = h2.request(url, 'GET', headers=headersDict)
>>> 
>>> response.status
200
>>> 
192.168.122.149 - - [31/May/2023:12:45:05 +0000] "GET /api/hosts HTTP/1.1" 200 69189 "-" "Python-httplib2/0.13.1 (gzip)"

Feedback/corrections are welcome, as this is my first take of an issue here in httplib2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant