Skip to content

Commit 9ceb6d4

Browse files
authored
added JWT issuers for audience auth for service interop and shared us… (#250)
* added JWT issuers for audience auth for service interop and shared user accounts * amended default value in line wioth code
1 parent 1036a17 commit 9ceb6d4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.env.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ SPEAKER_SERVICE_URL=http://${DOMAIN}:${SPEAKER_PORT}
5555
# JWT secret key - make this random and long
5656
AUTH_SECRET_KEY=your-super-secret-jwt-key-here-make-it-random-and-long
5757

58+
# JWT-token issuer ACCEPTED_ISSUERS can be a comma-separated list of accepted issuers
59+
# defaults to 'chronicle,ushadow' if not set
60+
# ACCEPTED_ISSUERS=chronicle,ushadow
61+
5862
# Admin account
5963
ADMIN_EMAIL=admin@example.com
6064
ADMIN_PASSWORD=secure-admin-password

backends/advanced/src/advanced_omi_backend/auth.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def _verify_configured(var_name: str, *, optional: bool = False) -> Optional[str
5050
ADMIN_PASSWORD = _verify_configured("ADMIN_PASSWORD")
5151
ADMIN_EMAIL = _verify_configured("ADMIN_EMAIL", optional=True) or "admin@example.com"
5252

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

5462
class UserManager(BaseUserManager[User, PydanticObjectId]):
5563
"""User manager with minimal customization for fastapi-users."""
@@ -100,7 +108,8 @@ async def get_user_manager(user_db=Depends(get_user_db)):
100108
def get_jwt_strategy() -> JWTStrategy:
101109
"""Get JWT strategy for token generation and validation."""
102110
return JWTStrategy(
103-
secret=SECRET_KEY, lifetime_seconds=JWT_LIFETIME_SECONDS
111+
secret=SECRET_KEY, lifetime_seconds=JWT_LIFETIME_SECONDS,
112+
token_audience=["fastapi-users:auth"] + ACCEPTED_ISSUERS
104113
)
105114

106115

0 commit comments

Comments
 (0)