From fdb8fb4b4cbc95e4ef648d53bcbe14d18606d541 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 18 Aug 2022 20:26:12 +0200 Subject: [PATCH] providers/oauth2: fix oauth2 requests being logged as unauthenticated Signed-off-by: Jens Langhammer --- authentik/providers/oauth2/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/authentik/providers/oauth2/utils.py b/authentik/providers/oauth2/utils.py index f938fb87e..b7975ba7e 100644 --- a/authentik/providers/oauth2/utils.py +++ b/authentik/providers/oauth2/utils.py @@ -10,7 +10,7 @@ from django.http.response import HttpResponseRedirect from django.utils.cache import patch_vary_headers from structlog.stdlib import get_logger -from authentik.core.middleware import KEY_USER +from authentik.core.middleware import CTX_AUTH_VIA, KEY_USER from authentik.events.models import Event, EventAction from authentik.providers.oauth2.errors import BearerTokenError from authentik.providers.oauth2.models import OAuth2Provider, RefreshToken @@ -166,6 +166,7 @@ def protected_resource_view(scopes: list[str]): ] = f'error="{error.code}", error_description="{error.description}"' return response kwargs["token"] = token + CTX_AUTH_VIA.set("oauth_token") response = view(request, *args, **kwargs) setattr(response, "ak_context", {}) response.ak_context[KEY_USER] = token.user.username