Skip to content

Commit

Permalink
Add a simple example of custom authentication in the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dpursehouse committed Jul 22, 2013
1 parent 5cdcf58 commit 62f0df4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/user/authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,24 @@ want, you can implement it yourself. Requests makes it easy to add your own
forms of authentication.

To do so, subclass :class:`requests.auth.AuthBase` and implement the
``__call__()`` method. When an authentication handler is attached to a request,
``__call__()`` method::

>>> import requests
>>> class MyAuth(requests.auth.AuthBase):
... def __call__(self, r):
... # Implement my authentication
... return r
...
>>> url = 'http://httpbin.org/get'
>>> requests.get(url, auth=MyAuth())
<Response [200]>

When an authentication handler is attached to a request,
it is called during request setup. The ``__call__`` method must therefore do
whatever is required to make the authentication work. Some forms of
authentication will additionally add hooks to provide further functionality.

Examples can be found under the `Requests organization`_ and in the
Further examples can be found under the `Requests organization`_ and in the
``auth.py`` file.

.. _OAuth: http://oauth.net/
Expand Down

0 comments on commit 62f0df4

Please sign in to comment.