From: David Pursehouse Date: Mon, 22 Jul 2013 00:09:26 +0000 (+0900) Subject: Add a simple example of custom authentication in the documentation X-Git-Tag: 2.0~15^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=62f0df4434df363435e3e3a9cac73ddfac4cd07c;p=services%2Fpython-requests.git Add a simple example of custom authentication in the documentation Refs #1471 --- diff --git a/docs/user/authentication.rst b/docs/user/authentication.rst index 7f62da6..af43bd2 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()) + + +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/