mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-11 04:58:33 +03:00
allows search to happen with API_TOKEN
This commit is contained in:
@@ -18,8 +18,19 @@ basic_security = HTTPBasic()
|
||||
bearer_security = HTTPBearer()
|
||||
|
||||
# --------------------- Bearer Auth
|
||||
ALLOW_ANY_EMAIL = "*"
|
||||
|
||||
|
||||
API_BEARER_TOKEN = os.environ.get("API_BEARER_TOKEN", "") # min length is 20 chars
|
||||
async def get_bearer_auth_token_or_jwt(credentials: HTTPAuthorizationCredentials = Depends(bearer_security)):
|
||||
# tries to use the static API_KEY and defaults to google JWT auth
|
||||
access_token = credentials.credentials
|
||||
if len(API_BEARER_TOKEN) >= 20:
|
||||
current_token_bytes = access_token.encode("utf8")
|
||||
is_correct_token = secrets.compare_digest(current_token_bytes, API_BEARER_TOKEN.encode("utf8"))
|
||||
if is_correct_token: return ALLOW_ANY_EMAIL # any email works
|
||||
return await get_bearer_auth(credentials)
|
||||
|
||||
async def get_bearer_auth(credentials: HTTPAuthorizationCredentials = Depends(bearer_security)):
|
||||
# validates the Bearer token in the case that it requires it
|
||||
access_token = credentials.credentials
|
||||
|
||||
Reference in New Issue
Block a user