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, )