|
13 | 13 | import time
|
14 | 14 | import os
|
15 | 15 | from hashlib import md5, sha256, sha512
|
16 |
| -from werkzeug.http import parse_authorization_header |
17 | 16 | from werkzeug.datastructures import WWWAuthenticate
|
| 17 | +from werkzeug.http import dump_header |
| 18 | + |
| 19 | +try: |
| 20 | + from werkzeug.http import parse_authorization_header |
| 21 | +except ImportError: # werkzeug < 2.3 |
| 22 | + from werkzeug.datastructures import Authorization |
| 23 | + parse_authorization_header = Authorization.from_header |
18 | 24 |
|
19 | 25 | from flask import request, make_response
|
20 | 26 | from six.moves.urllib.parse import urlparse, urlunparse
|
@@ -466,9 +472,14 @@ def digest_challenge_response(app, qop, algorithm, stale = False):
|
466 | 472 | ]), algorithm)
|
467 | 473 | opaque = H(os.urandom(10), algorithm)
|
468 | 474 |
|
469 |
| - auth = WWWAuthenticate("digest") |
470 |
| - auth. set_digest( '[email protected]', nonce, opaque=opaque, |
471 |
| - qop=('auth', 'auth-int') if qop is None else (qop,), algorithm=algorithm) |
472 |
| - auth.stale = stale |
| 475 | + values = { |
| 476 | + |
| 477 | + 'nonce': nonce, |
| 478 | + 'opaque': opaque, |
| 479 | + 'qop': dump_header(('auth', 'auth-int') if qop is None else (qop,)), |
| 480 | + 'algorithm': algorithm, |
| 481 | + 'stale': stale, |
| 482 | + } |
| 483 | + auth = WWWAuthenticate("digest", values=values) |
473 | 484 | response.headers['WWW-Authenticate'] = auth.to_header()
|
474 | 485 | return response
|
0 commit comments