providers/oauth2: fix oauth2 requests being logged as unauthenticated
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
d8a68407f9
commit
fdb8fb4b4c
|
@ -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
|
||||
|
|
Reference in a new issue