From 5cdcf58b3b57a9407af8280a9ab14f63742e339c Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 22 Jul 2013 09:08:47 +0900 Subject: [PATCH 1/2] Wrap long lines in the authentication documentation --- docs/user/authentication.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/user/authentication.rst b/docs/user/authentication.rst index 4b29007c..7f62da6c 100644 --- a/docs/user/authentication.rst +++ b/docs/user/authentication.rst @@ -58,7 +58,8 @@ and Requests supports this out of the box as well:: OAuth 1 Authentication ---------------------- -A common form of authentication for several web APIs is OAuth. The ``requests-oauthlib`` library allows Requests users to easily make OAuth authenticated requests:: +A common form of authentication for several web APIs is OAuth. The ``requests-oauthlib`` +library allows Requests users to easily make OAuth authenticated requests:: >>> import requests >>> from requests_oauthlib import OAuth1 @@ -71,7 +72,8 @@ A common form of authentication for several web APIs is OAuth. The ``requests-oa For more information on how to OAuth flow works, please see the official `OAuth`_ website. -For examples and documentation on requests-oauthlib, please see the `requests_oauthlib`_ repository on GitHub +For examples and documentation on requests-oauthlib, please see the `requests_oauthlib`_ +repository on GitHub Other Authentication From 62f0df4434df363435e3e3a9cac73ddfac4cd07c Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 22 Jul 2013 09:09:26 +0900 Subject: [PATCH 2/2] Add a simple example of custom authentication in the documentation Refs #1471 --- docs/user/authentication.rst | 16 ++++++++++++++-- 1 file 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()) + + +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/