Support DigestAuth with "x-www-authenticate" in first response header
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- python
- Ambito
- authentication
Direzione di ricerca
Inizia in httpx/_auth.py, nella gestione delle risposte di DigestAuth a cui fa riferimento l’issue, quindi riproduci l’esempio Python fornito oppure esamina l’header della risposta 401 mostrato. Il lavoro è completato quando DigestAuth può estrarre una challenge Digest da X-WWW-Authenticate oltre che dall’header standard www-authenticate senza interrompere il flusso esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Originally opened by
@kiryphon 2024-09-19 14:21:02 in encode/httpx
The Fronius inverter for photovoltaic systems uses for its local REST API digest authentication.
It uses its initial response header "X-WWW-Authenticate" instead of "www-authenticate" and hence make the httpx request fail.
Here an initial curl command with the response header:
❯ curl -I "http://192.168.1.141/config/emrs"
HTTP/1.1 401 Unauthorized
X-WWW-Authenticate: Digest realm="Webinterface area", charset="UTF-8", algorithm=MD5, nonce="66ec2f8d:36a65537553cf788606762854336a0b3", qop="auth"
Content-Type: text/html
Content-Length: 347
Date: Thu, 19 Sep 2024 14:05:01 GMT
Server: webserver
httpx 0.27.2 fails to extract X-WWW-Authenticate with nonce, qop, algorithm, realm in
My script
import httpx
url = "http://192.168.1.141/config/emrs" # adjust IP to that one of your inverter
user = "technician"
pw = <INSERT PW>
auth = httpx.DigestAuth(user,pw)
with httpx.Client(auth=auth) as client:
r = client.get(url)
print(r.status_code)
print(r.json()['priorities'])
r = client.get(url)
print(r.status_code)
print(r.json()['priorities'])
runs only with following quick diff
❯ git diff
diff --git a/httpx/_auth.py b/httpx/_auth.py
index b03971a..fb6ad69 100644
--- a/httpx/_auth.py
+++ b/httpx/_auth.py
@@ -198,12 +198,22 @@ class DigestAuth(Auth):
response = yield request
- if response.status_code != 401 or "www-authenticate" not in response.headers:
+ auth_strings = [ "www-authenticate", "x-www-authenticate" ]
+ auth_string = False
+ for a in auth_strings:
+ if a in response.headers:
+ if auth_string == False:
+ auth_string = a
+ else:
+ message = "Malformed Digest WWW-Authenticate response header"
+ raise ProtocolError(message, request=request)
+
+ if response.status_code != 401 or auth_string == False:
# If the response is not a 401 then we don't
# need to build an authenticated request.
return
- for auth_header in response.headers.get_list("www-authenticate"):
+ for auth_header in response.headers.get_list(auth_string):
if auth_header.lower().startswith("digest "):
break
else:
Note, this diff is only to show to me that it works. I did not follow any coding guidelines of this project.
For reference, here a couple of projects which have written their custom digest authorization to handle the Fronius reponse header using the request library:
- https://github.com/wiggal/GEN24_Ladesteuerung/blob/main/FUNCTIONS/httprequest.py
- https://github.com/muexxl/batcontrol/blob/main/fronius/fronius.py#L326-L361
- https://github.com/jakkaj/ha_fronius_set_service/blob/main/fronius_settings_service/script.py#L28-L112
- https://github.com/sergioperez/fronius-auth-proxy/blob/master/makeRequest.js
I am not sure how common it is to use X-WWW-Authenticate. Google did not return many results:
However, I still think supporting this deviation might be acceptable. If Fronius screwed this up more heavily than I think, I understand that httpx cannot support all quirks of all digest implementations.
- Lingua principale
- Python
- Stelle
- 1.6k
- Fork
- 103
- Merge medio
- 1g 19h
- PR unite (30g)
- 25
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pydantic/httpx2
-
Please revert aiter_bytes signature to AsyncIteratorForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
pydantic/httpx2#1158 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Export AutoBackendForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
pydantic/httpx2#1131 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Mention header name error message for invalid header encodingsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
pydantic/httpx2#864 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pydantic/httpx2
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
OCA/account-invoicing#2529 ·
I maintainer di solito rispondono entro 1 giorno
-
area/ci
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
ImageGen generate-batch aborts valid JSONL jobs containing a Unicode line separator in poster textApertabug imagen skills
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Email validation accepts a trailing newlineForse già presa @marcello-pichini l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno