utils: add simple HTTP Bearer authentication class

This commit is contained in:
Serghei Mihai 2019-05-21 10:26:32 +02:00
parent f424478578
commit a7e7814002
1 changed files with 15 additions and 0 deletions

View File

@ -68,3 +68,18 @@ class HawkAuth(AuthBase):
def __call__(self, r):
r.headers['Authorization'] = self.get_authorization_header(r)
return r
class HttpBearerAuth(AuthBase):
def __init__(self, token):
self.token = token
def __eq__(self, other):
return self.token == getattr(other, 'token', None)
def __ne__(self, other):
return not self == other
def __call__(self, r):
r.headers['Authorization'] = 'Bearer ' + self.token
return r