| Akron | ca9bd98 | 2016-12-06 16:59:57 +0100 | [diff] [blame^] | 1 | from requests.auth import AuthBase | 
|  | 2 |  | 
|  | 3 | __author__ = 'hanl' | 
|  | 4 |  | 
|  | 5 |  | 
|  | 6 | class Oauth2Auth(AuthBase): | 
|  | 7 | ''' | 
|  | 8 | starts needs to match the provider name | 
|  | 9 | ''' | 
|  | 10 | def __init__(self, token=None): | 
|  | 11 | self.token = token | 
|  | 12 |  | 
|  | 13 | def __call__(self, r): | 
|  | 14 | if self.token is not None: | 
|  | 15 | r.headers['Authorization'] = "OAuth2 Bearer " + self.token | 
|  | 16 | return r | 
|  | 17 |  | 
|  | 18 |  | 
|  | 19 | class CustomAuth(AuthBase): | 
|  | 20 | def __init__(self, token=None): | 
|  | 21 | self.token = token | 
|  | 22 |  | 
|  | 23 | def __call__(self, r): | 
|  | 24 | if self.token is not None: | 
|  | 25 | r.headers['Authorization'] = "api_token " + self.token | 
|  | 26 | return r |