Skip to content
Snippets Groups Projects
Dependencies.py 587 B
Newer Older
  • Learn to ignore specific revisions
  • Robert Goldmann's avatar
    Robert Goldmann committed
    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()
    
    Robert Goldmann's avatar
    Robert Goldmann committed
    
    
    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):
    
    Robert Goldmann's avatar
    Robert Goldmann committed
            raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail='apiKey invalid')