From 88057db0b0874160812383b66e25a2e51b9109a0 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:17:10 +0100 Subject: [PATCH] providers/oauth2: set auth_via for token and other endpoints (cherry-pick #7417) (#7427) providers/oauth2: set auth_via for token and other endpoints (#7417) Signed-off-by: Jens Langhammer Co-authored-by: Jens L --- authentik/providers/oauth2/utils.py | 1 + authentik/providers/oauth2/views/token.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/authentik/providers/oauth2/utils.py b/authentik/providers/oauth2/utils.py index cc7a86519..513994b80 100644 --- a/authentik/providers/oauth2/utils.py +++ b/authentik/providers/oauth2/utils.py @@ -188,6 +188,7 @@ def authenticate_provider(request: HttpRequest) -> Optional[OAuth2Provider]: if client_id != provider.client_id or client_secret != provider.client_secret: LOGGER.debug("(basic) Provider for basic auth does not exist") return None + CTX_AUTH_VIA.set("oauth_client_secret") return provider diff --git a/authentik/providers/oauth2/views/token.py b/authentik/providers/oauth2/views/token.py index dc08eb526..146978fe1 100644 --- a/authentik/providers/oauth2/views/token.py +++ b/authentik/providers/oauth2/views/token.py @@ -17,6 +17,7 @@ from jwt import PyJWK, PyJWT, PyJWTError, decode from sentry_sdk.hub import Hub from structlog.stdlib import get_logger +from authentik.core.middleware import CTX_AUTH_VIA from authentik.core.models import ( USER_ATTRIBUTE_EXPIRES, USER_ATTRIBUTE_GENERATED, @@ -448,6 +449,7 @@ class TokenView(View): if not self.provider: LOGGER.warning("OAuth2Provider does not exist", client_id=client_id) raise TokenError("invalid_client") + CTX_AUTH_VIA.set("oauth_client_secret") self.params = TokenParams.parse(request, self.provider, client_id, client_secret) with Hub.current.start_span(