mirror of
https://github.com/RaspAP/raspap-webgui.git
synced 2024-11-25 17:10:26 +00:00
24 lines
666 B
Python
24 lines
666 B
Python
import os
|
|
from fastapi.security.api_key import APIKeyHeader
|
|
from fastapi import Security, HTTPException
|
|
from starlette.status import HTTP_403_FORBIDDEN
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
apikey=os.getenv('RASPAP_API_KEY')
|
|
#if env not set, set the api key to "insecure"
|
|
if apikey == None:
|
|
apikey = "insecure"
|
|
|
|
print(apikey)
|
|
api_key_header = APIKeyHeader(name="access_token", auto_error=False)
|
|
|
|
async def get_api_key(api_key_header: str = Security(api_key_header)):
|
|
if api_key_header ==apikey:
|
|
return api_key_header
|
|
else:
|
|
raise HTTPException(
|
|
status_code=HTTP_403_FORBIDDEN, detail="403: Unauthorized"
|
|
)
|
|
|