From 21ae809dd6e08d1b5823373637ef17805640d73a Mon Sep 17 00:00:00 2001 From: yelinz Date: Fri, 13 Jan 2023 14:18:19 +0100 Subject: [PATCH] fix(auth): add userinfo to authenticated user --- document_merge_service/api/authentication.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/document_merge_service/api/authentication.py b/document_merge_service/api/authentication.py index e7bd5e65..6e525b29 100644 --- a/document_merge_service/api/authentication.py +++ b/document_merge_service/api/authentication.py @@ -27,9 +27,13 @@ def __str__(self): class AuthenticatedUser(AnonymousUser): - def __init__(self, username, groups): - self.username = username + def __init__(self, userinfo): + self.username = userinfo["sub"] + groups = [] + if settings.OIDC_GROUPS_CLAIM: + groups = userinfo[settings.OIDC_GROUPS_CLAIM] self.groups = groups + self.userinfo = userinfo @property def is_authenticated(self): @@ -94,12 +98,8 @@ def authenticate(self, request): timeout=settings.OIDC_BEARER_TOKEN_REVALIDATION_TIME, ) - groups = [] - if settings.OIDC_GROUPS_CLAIM: - groups = userinfo[settings.OIDC_GROUPS_CLAIM] - return ( - AuthenticatedUser(userinfo["sub"], groups), + AuthenticatedUser(userinfo), token, )