Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions backend/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
router = APIRouter(tags=["Login"])

# API Key security scheme for Swagger UI
api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
api_key_header = APIKeyHeader(name="key", auto_error=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The API key header name has been changed from X-API-Key to key. While the X- prefix for custom headers is being deprecated, X-API-Key is a widely understood de-facto standard. Using a generic name like key is not recommended as it is not descriptive and could potentially conflict with other headers. It is better to use a more specific name. If you want to avoid the X- prefix, consider a name like OVPanel-API-Key. Reverting to X-API-Key would be the clearest and most conventional choice.

Suggested change
api_key_header = APIKeyHeader(name="key", auto_error=False)
api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)


def verify_password(plain_password, hashed_password):
return pwd_context.verify(plain_password, hashed_password)
Expand Down Expand Up @@ -88,11 +88,11 @@ def get_current_user(token: str = Depends(oauth2_scheme)):

def verify_api_key(api_key: Optional[str] = Depends(api_key_header)) -> dict:
"""
Verify API key from X-API-Key header.
Verify API key from key header.
This is for external integrations that need to access the API.

Usage:
Add header: X-API-Key: your-api-key-here
Add header: key: your-api-key-here

Returns:
dict with authentication info if valid
Expand All @@ -109,7 +109,7 @@ def verify_api_key(api_key: Optional[str] = Depends(api_key_header)) -> dict:
if not api_key:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Missing X-API-Key header",
detail="Missing key header",
headers={"WWW-Authenticate": "ApiKey"},
)

Expand Down Expand Up @@ -169,7 +169,7 @@ def verify_jwt_or_api_key(
# Neither authentication method worked
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials. Provide either valid JWT Bearer token or X-API-Key header",
detail="Could not validate credentials. Provide either valid JWT Bearer token or key header",
headers={"WWW-Authenticate": "Bearer, ApiKey"},
)