-
Notifications
You must be signed in to change notification settings - Fork 1
/
authentication.py
28 lines (22 loc) · 962 Bytes
/
authentication.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
28
import jwt
import os
from fastapi import Security, HTTPException
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
SERVICE_ALLOWLIST = ["SSCA"]
SECRET_KEY = os.getenv("GENAI_SERVICE_SECRET")
security = HTTPBearer()
def authorize_request(authorization:
HTTPAuthorizationCredentials = Security(security),
):
if authorization.scheme != "Bearer":
print("Invalid authorization scheme")
# try:
# token = authorization.credentials
# claims = jwt.decode(token, options={"verify_signature": False})
# if ('sub' not in claims or
# claims['sub'] not in SERVICE_ALLOWLIST):
# raise HTTPException(status_code=401, detail="Invalid client")
# jwt.decode(token, SECRET_KEY, algorithms="HS256")
# return claims['sub']
# except jwt.exceptions.PyJWTError as e:
# raise HTTPException(status_code=401, detail=str(e))