feat: API key auth for agents (create/list/revoke) + dual auth (JWT or API key)

This commit is contained in:
Zhi
2026-02-22 09:05:05 +00:00
parent 1d5d8add3d
commit 1e9c6fd2f8
2 changed files with 98 additions and 0 deletions

15
app/models/apikey.py Normal file
View File

@@ -0,0 +1,15 @@
from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey
from sqlalchemy.sql import func
from app.core.config import Base
class APIKey(Base):
__tablename__ = "api_keys"
id = Column(Integer, primary_key=True, index=True)
key = Column(String(64), unique=True, nullable=False, index=True)
name = Column(String(100), nullable=False) # e.g. "agent-zhi", "agent-lyn"
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
is_active = Column(Boolean, default=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
last_used_at = Column(DateTime(timezone=True), nullable=True)