Skip to content
Myr

Add a simple example of custom authentication in the documentation

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Refs #1471

authored by David Pursehouse · committed by David Pursehouse · parent 5cdcf58 · Browse files · 1 file+14 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−2 removed

  • other:+14 added−2 removed

1 file+14 added−2 removed

modified:docs/user/authentication.rst+14 added-2 removed
98 unmodified lines
99want, you can implement it yourself. Requests makes it easy to add your own100forms of authentication.101102To do so, subclass :class:`requests.auth.AuthBase` and implement the103``__call__()`` method. When an authentication handler is attached to a request,103``__call__()`` method::104105 >>> import requests106 >>> class MyAuth(requests.auth.AuthBase):107 ... def __call__(self, r):108 ... # Implement my authentication109 ... return r110 ...111 >>> url = 'http://httpbin.org/get'112 >>> requests.get(url, auth=MyAuth())113 <Response [200]>114115When an authentication handler is attached to a request,116it is called during request setup. The ``__call__`` method must therefore do117whatever is required to make the authentication work. Some forms of118authentication will additionally add hooks to provide further functionality.119108Examples can be found under the `Requests organization`_ and in the120Further examples can be found under the `Requests organization`_ and in the121``auth.py`` file.122123.. _OAuth: http://oauth.net/124.. _requests_oauthlib: https://github.com/requests/requests-oauthlib
4 unmodified lines