providers/oauth2: fix oauth2 requests being logged as unauthenticated

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-08-18 20:26:12 +02:00
parent d8a68407f9
commit fdb8fb4b4c
1 changed files with 2 additions and 1 deletions

View File

@ -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