-
Notifications
You must be signed in to change notification settings - Fork 2
/
auth.py
27 lines (19 loc) · 798 Bytes
/
auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import hashlib
import os
from functools import wraps
from flask import request
from error_handlers import _make_response
FORTNITE_REPLAY_ELIM_API_AUTH_DIGEST = os.getenv("FORTNITE_REPLAY_ELIM_API_AUTH_DIGEST")
def validate(f):
""" Validate headers for incoming requests """
@wraps(f)
def validate(*args, **kwargs):
# Validate header
if "API-TOKEN" not in request.headers:
return _make_response("Authentication header not provided", 400)
req_api_token = request.headers.get("API-TOKEN", "")
req_api_digest = hashlib.sha512(req_api_token.encode()).hexdigest()
if req_api_digest != FORTNITE_REPLAY_ELIM_API_AUTH_DIGEST:
return _make_response("Unauthorized", 401)
return f(*args, **kwargs)
return validate