Skip to content
Snippets Groups Projects
Select Git revision
  • 45b9d0bb0500fd4593f3bdf9cf3b1e1b07b18ea1
  • master default
  • renovate/fastapi-0.x
  • v2.21.0
  • v2.20.1
  • v2.20.0
  • v2.19.0
  • v2.18.1
  • v2.18.0
  • v2.17.0
  • v2.16.0
  • v2.15.0
  • v2.14.0
  • v2.13.1
  • v2.13.0
  • v2.12.0
  • v2.11.0
  • v2.10.0
  • v2.9.0
  • v2.8.0
  • v2.7.0
  • v2.6.0
  • v2.5.0
23 results

Dependencies.py

Blame
  • Dependencies.py 587 B
    import secrets
    
    from fastapi import Security, HTTPException
    from fastapi.security import APIKeyHeader
    from starlette.status import HTTP_403_FORBIDDEN
    
    from logic.databaseNew.Database import SessionLocal
    
    
    def get_database():
        db = SessionLocal()
        try:
            yield db
        finally:
            db.close()
    
    
    API_KEY_HEADER = APIKeyHeader(name='apiKey')
    
    
    async def check_api_key(apiKey: str = Security(API_KEY_HEADER)):
        from main import API_KEY
        if not secrets.compare_digest(API_KEY, apiKey):
            raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail='apiKey invalid')