summaryrefslogtreecommitdiff
path: root/docs/user/authentication.rst
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2013-07-22 09:09:26 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2013-07-22 09:14:33 +0900
commit62f0df4434df363435e3e3a9cac73ddfac4cd07c (patch)
tree775d1b5e656c28f41d61a1987b716684fe1da781 /docs/user/authentication.rst
parent5cdcf58b3b57a9407af8280a9ab14f63742e339c (diff)
downloadpython-requests-62f0df4434df363435e3e3a9cac73ddfac4cd07c.tar.gz
Add a simple example of custom authentication in the documentation
Refs #1471
Diffstat (limited to 'docs/user/authentication.rst')
-rw-r--r--docs/user/authentication.rst16
1 files changed, 14 insertions, 2 deletions
diff --git a/docs/user/authentication.rst b/docs/user/authentication.rst
index 7f62da6c..af43bd29 100644
--- a/docs/user/authentication.rst
+++ b/docs/user/authentication.rst
@@ -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/