@@ -3,21 +3,50 @@ Authentication
33
44This section covers how to do authentication with Uplink.
55
6+ In v0.4, we added the :py:attr: `auth ` parameter to the
7+ :py:class: `uplink.Consumer ` constructor which allowed for
8+ sending HTTP Basic Authentication with all requests.
9+
10+ In v0.9, we added more auth methods which can be used in the
11+ :py:attr: `auth ` parameter of the :py:class: `uplink.Consumer `
12+ constructor. If you are using an uplink-based API library,
13+ the library might extend these methods with additional
14+ API-specific auth methods.
15+
16+ Some common auth methods are described below, but for a
17+ complete list of auth methods provided with Uplink, see
18+ the :ref: `auth_methods ` reference.
19+
620.. _basic_authentication :
721
822Basic Authentication
923--------------------
1024
11- In v0.4, we added the :py:attr: `auth ` parameter to the
12- :py:class: `uplink.Consumer ` constructor.
13-
14- Now it's simple to construct a consumer that uses HTTP Basic
25+ It's simple to construct a consumer that uses HTTP Basic
1526Authentication with all requests:
1627
1728.. code-block :: python
1829
1930 github = GitHub(BASE_URL , auth = (" user" , " pass" ))
2031
32+ Proxy Authentication
33+ --------------------
34+
35+ If you need to supply credentials for an intermediate proxy
36+ in addition to the API's HTTP Basic Authentication, use
37+ :py:class: `uplink.auth.MultiAuth ` with :py:class: `uplink.auth.ProxyAuth `
38+ and :py:class: `uplink.auth.BasicAuth `.
39+
40+ .. code-block :: python
41+
42+ from uplink.auth import BasicAuth, MultiAuth, ProxyAuth
43+
44+ auth_methods = MultiAuth(
45+ ProxyAuth(" proxy_user" , " proxy_pass" ),
46+ BasicAuth(" user" , " pass" )
47+ )
48+ github = GitHub(BASE_URL , auth = auth_methods)
49+
2150 Other Authentication
2251--------------------
2352
@@ -39,10 +68,31 @@ through the consumer's :obj:`session <uplink.Consumer.session>` property:
3968
4069 class GitHub (Consumer ):
4170
42- def __init__ (self , access_token ):
71+ def __init__ (self , base_url , access_token ):
72+ super (GitHub, self ).__init__ (base_url = base_url)
4373 self .session.params[" access_token" ] = access_token
4474 ...
4575
76+ As of v0.9, you can also supply these tokens via the :py:attr: `auth `
77+ parameter of the :py:class: `uplink.Consumer ` constructor. This is
78+ like adding the token to the session (above) so that the token is
79+ sent as part of every request.
80+
81+ .. code-block :: python
82+
83+ from uplink.auth import ApiTokenParam, ApiTokenHeader, BearerToken
84+
85+ # Passing an auth token as a query parameter
86+ token_auth = ApiTokenParam(" access_token" , access_token)
87+ github = GitHub(BASE_URL , auth = token_auth)
88+
89+ # Passing the token as a header value
90+ token_auth = ApiTokenHeader(" Access-Token" , access_token)
91+ github = GitHub(BASE_URL , auth = token_auth)
92+
93+ # Passing a Bearer auth token
94+ bearer_auth = BearerToken(access_token)
95+ github = GitHub(BASE_URL , auth = bearer_auth)
4696
4797 Using Auth Support for Requests and aiohttp
4898-------------------------------------------
0 commit comments