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
19 changes: 16 additions & 3 deletions backends/advanced/src/advanced_omi_backend/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def _verify_configured(var_name: str, *, optional: bool = False) -> Optional[str
ADMIN_PASSWORD = _verify_configured("ADMIN_PASSWORD")
ADMIN_EMAIL = _verify_configured("ADMIN_EMAIL", optional=True) or "admin@example.com"

# Accepted token issuers - comma-separated list of services whose tokens we accept
# Default: "chronicle,ushadow" (accept tokens from both chronicle and ushadow)
ACCEPTED_ISSUERS = [
iss.strip()
for iss in os.getenv("ACCEPTED_TOKEN_ISSUERS", "chronicle,ushadow").split(",")
if iss.strip()
]
logger.info(f"Accepting tokens from issuers: {ACCEPTED_ISSUERS}")

class UserManager(BaseUserManager[User, PydanticObjectId]):
"""User manager with minimal customization for fastapi-users."""
Expand Down Expand Up @@ -98,12 +106,17 @@ async def get_user_manager(user_db=Depends(get_user_db)):


def get_jwt_strategy() -> JWTStrategy:
"""Get JWT strategy for token generation and validation."""
"""Get JWT strategy for token generation and validation.

Configures token_audience from ACCEPTED_ISSUERS plus fastapi-users:auth
for Chronicle's own tokens.
"""
return JWTStrategy(
secret=SECRET_KEY, lifetime_seconds=JWT_LIFETIME_SECONDS
secret=SECRET_KEY,
lifetime_seconds=JWT_LIFETIME_SECONDS,
token_audience=["fastapi-users:auth"] + ACCEPTED_ISSUERS,
)


def generate_jwt_for_user(user_id: str, user_email: str) -> str:
"""Generate a JWT token for a user to authenticate with external services.

Expand Down
Loading