summaryrefslogtreecommitdiff
path: root/www/py-httpbin/files/patch-httpbin_helpers.py
blob: f271fc3541272732170e37e90f2e374929999b4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--- httpbin/helpers.py.orig	2023-08-28 22:56:17 UTC
+++ httpbin/helpers.py
@@ -13,7 +13,15 @@ from hashlib import md5, sha256, sha512
 import time
 import os
 from hashlib import md5, sha256, sha512
-from werkzeug.http import parse_authorization_header
+# Can be removed when: https://github.com/psf/httpbin/issues/36 is closed
+# See also (version order is wrong):
+# https://src.fedoraproject.org/rpms/python-httpbin/c/54fe8e1f94f208b16ef0588e4eb69aaa107e9867?branch=rawhide
+from werkzeug.http import dump_header
+try:
+    from werkzeug.datastructures import Authorization
+    parse_authorization_header = Authorization.from_header
+except ImportError: # werkzeug < 2.3
+    from werkzeug.http import parse_authorization_header
 from werkzeug.datastructures import WWWAuthenticate
 
 from flask import request, make_response
@@ -466,9 +474,17 @@ def digest_challenge_response(app, qop, algorithm, sta
     ]), algorithm)
     opaque = H(os.urandom(10), algorithm)
 
-    auth = WWWAuthenticate("digest")
-    auth.set_digest('me@kennethreitz.com', nonce, opaque=opaque,
-                    qop=('auth', 'auth-int') if qop is None else (qop,), algorithm=algorithm)
-    auth.stale = stale
+    # Can be removed when: https://github.com/psf/httpbin/issues/36 is closed
+    # See also:
+    # https://src.fedoraproject.org/rpms/python-httpbin/c/54fe8e1f94f208b16ef0588e4eb69aaa107e9867?branch=rawhide
+    values = {
+        'realm': 'me@kennethreitz.com',
+        'nonce': nonce,
+        'opaque': opaque,
+        'qop': dump_header(('auth', 'auth-int') if qop is None else (qop,)),
+        'algorithm': algorithm,
+        'stale': stale,
+    }
+    auth = WWWAuthenticate("digest", values=values) 
     response.headers['WWW-Authenticate'] = auth.to_header()
     return response