Skip to content
Snippets Groups Projects

Add standard Bearer token header instedad of access_token header

Merged Mohammad Torkashvand requested to merge fix/NAT-425-add-gso-api-key into develop
2 files
+ 10
6
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 6
4
"""Manage API key validation for FastAPI routes."""
"""Manage API key validation for FastAPI routes."""
from fastapi import Depends, HTTPException, status
from fastapi import Depends, HTTPException, status
from fastapi.security.api_key import APIKeyHeader
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from gso.settings import load_oss_params
from gso.settings import load_oss_params
API_KEY_NAME = "access_token"
security = HTTPBearer()
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=True)
async def get_api_key(api_key: str = Depends(api_key_header)) -> str:
async def get_api_key(
 
credentials: HTTPAuthorizationCredentials = Depends(security), # noqa: B008
 
) -> str:
"""Validate the provided API key against known third-party keys and returns it if valid, else raises HTTP 403."""
"""Validate the provided API key against known third-party keys and returns it if valid, else raises HTTP 403."""
settings = load_oss_params()
settings = load_oss_params()
 
api_key = credentials.credentials
# TODO: This is a simulated database of API keys which should be replace with a real one
# TODO: This is a simulated database of API keys which should be replace with a real one
if api_key in settings.THIRD_PARTY_API_KEYS.values():
if api_key in settings.THIRD_PARTY_API_KEYS.values():
Loading