Skip to content

Commit

Permalink
Merge pull request #131 from jameshilliard/HTTPDigestAuth
Browse files Browse the repository at this point in the history
HTTP Digest authentication support
  • Loading branch information
glyph authored Jun 19, 2024
2 parents c9f0bae + a688242 commit 22a776d
Show file tree
Hide file tree
Showing 8 changed files with 711 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'

- uses: actions/cache@v4
with:
Expand All @@ -42,7 +42,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"

- uses: actions/cache@v4
with:
Expand Down
16 changes: 16 additions & 0 deletions docs/examples/digest_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from twisted.internet.task import react
from _utils import print_response

import treq
from treq.auth import HTTPDigestAuth


def main(reactor, *args):
d = treq.get(
'http://httpbin.org/digest-auth/auth/treq/treq',
auth=HTTPDigestAuth('treq', 'treq')
)
d.addCallback(print_response)
return d

react(main, [])
21 changes: 21 additions & 0 deletions docs/howto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ The ``auth`` argument should be a tuple of the form ``('username', 'password')``

Full example: :download:`basic_auth.py <examples/basic_auth.py>`

HTTP Digest authentication is supported by passing an instance of
:py:class:`treq.auth.HTTPDigestAuth` to any of the request functions by using the `auth` keyword argument.
We support only "auth" QoP as defined at `RFC 2617`_
or simple `RFC 2069`_ without QoP at the moment. Treq takes care of
caching HTTP digest credentials — after authorizing any URL/method pair,
the library will use the initially received HTTP digest credentials on that endpoint
for subsequent requests, and will not perform any redundant requests to obtain the
credentials.

:py:class:`treq.auth.HTTPDigestAuth` class accepts ``username`` and ``password``
as constructor arguments.

.. literalinclude:: examples/digest_auth.py
:linenos:
:lines: 5-14

Full example: :download:`digest_auth.py <examples/digest_auth.py>`

.. _RFC 2617: http://www.ietf.org/rfc/rfc2617.txt
.. _RFC 2069: http://www.ietf.org/rfc/rfc2069.txt

Redirects
---------

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Here is a list of `requests`_ features and their status in treq.
+----------------------------------+----------+----------+
| Basic Authentication | yes | yes |
+----------------------------------+----------+----------+
| Digest Authentication | yes | no |
| Digest Authentication | yes | yes |
+----------------------------------+----------+----------+
| Elegant Key/Value Cookies | yes | yes |
+----------------------------------+----------+----------+
Expand Down
Loading

0 comments on commit 22a776d

Please sign in to comment.