From 60b483c420d849a748c5fe0a5643eba10a5c78e9 Mon Sep 17 00:00:00 2001 From: thijsvanwinden Date: Mon, 13 Jan 2025 16:16:19 +0100 Subject: [PATCH] Make user and claims model configurable Currently the claims and user are not configurable which is often required for other applications. This enables extension of the claims and user in a simple manner. --- src/fastapi_zitadel_auth/auth.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fastapi_zitadel_auth/auth.py b/src/fastapi_zitadel_auth/auth.py index f1d9e77..8974c39 100644 --- a/src/fastapi_zitadel_auth/auth.py +++ b/src/fastapi_zitadel_auth/auth.py @@ -37,6 +37,9 @@ class ZitadelAuth(SecurityBase): Zitadel OAuth2 authentication using bearer token """ + user_model: AuthenticatedUser = AuthenticatedUser + claims_model: ZitadelClaims = ZitadelClaims + def __init__(self, config: AuthConfig) -> None: """ Initialize the ZitadelAuth object @@ -93,8 +96,8 @@ async def __call__( ) # Create the authenticated user object and attach it to starlette.request.state - user = AuthenticatedUser( - claims=ZitadelClaims.model_validate(verified_claims), + user = self.user_model( + claims=self.claims_model.model_validate(verified_claims), access_token=access_token, ) request.state.user = user