mirror of
https://github.com/alerta/alerta.git
synced 2025-02-04 21:58:31 +00:00
25 lines
672 B
Python
25 lines
672 B
Python
from flask import Request, current_app
|
|
from mohawk import Receiver
|
|
|
|
|
|
def get_credentials(key_id: str):
|
|
credentials_map = {creds['id']: creds for creds in current_app.config['HMAC_AUTH_CREDENTIALS']}
|
|
if key_id in credentials_map:
|
|
return credentials_map[key_id]
|
|
else:
|
|
raise LookupError('Unknown sender')
|
|
|
|
|
|
class HmacAuth:
|
|
|
|
@staticmethod
|
|
def authenticate(r: Request):
|
|
return Receiver(
|
|
get_credentials,
|
|
r.headers.get('Authorization'),
|
|
url=r.url,
|
|
method=r.method,
|
|
content=r.data,
|
|
content_type=r.content_type,
|
|
timestamp_skew_in_seconds=300
|
|
)
|