feat: implement AI model API proxy service
This commit is contained in:
36
backend/app/services/auth.py
Normal file
36
backend/app/services/auth.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Authentication service."""
|
||||
import aiosqlite
|
||||
from typing import Optional
|
||||
from ..database import db_connection
|
||||
from ..models import ClientKey
|
||||
|
||||
|
||||
class AuthService:
|
||||
"""Service for client key authentication."""
|
||||
|
||||
@staticmethod
|
||||
async def validate_key(api_key: str) -> Optional[ClientKey]:
|
||||
"""Validate a client API key.
|
||||
|
||||
Args:
|
||||
api_key: The API key to validate
|
||||
|
||||
Returns:
|
||||
ClientKey if valid and active, None otherwise
|
||||
"""
|
||||
async with db_connection() as db:
|
||||
cursor = await db.execute(
|
||||
"""SELECT id, key, name, is_active, created_at
|
||||
FROM client_keys WHERE key = ?""",
|
||||
(api_key,)
|
||||
)
|
||||
row = await cursor.fetchone()
|
||||
if row and row["is_active"]:
|
||||
return ClientKey(
|
||||
id=row["id"],
|
||||
key=row["key"],
|
||||
name=row["name"],
|
||||
is_active=row["is_active"],
|
||||
created_at=row["created_at"]
|
||||
)
|
||||
return None
|
||||
Reference in New Issue
Block a user