From 7257108091d1fd2e062efdf0f29b6ddb0047200e Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 3 Jul 2021 16:11:49 +0200 Subject: [PATCH] sources/oauth: create configuration error event when profile can't be parsed as json Signed-off-by: Jens Langhammer --- authentik/sources/oauth/views/callback.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/authentik/sources/oauth/views/callback.py b/authentik/sources/oauth/views/callback.py index fa6d9b735..c8d8fc37e 100644 --- a/authentik/sources/oauth/views/callback.py +++ b/authentik/sources/oauth/views/callback.py @@ -1,4 +1,5 @@ """OAuth Callback Views""" +from json import JSONDecodeError from typing import Any, Optional from django.conf import settings @@ -10,6 +11,7 @@ from django.views.generic import View from structlog.stdlib import get_logger from authentik.core.sources.flow_manager import SourceFlowManager +from authentik.events.models import Event, EventAction from authentik.sources.oauth.models import OAuthSource, UserOAuthSourceConnection from authentik.sources.oauth.views.base import OAuthClientMixin @@ -42,8 +44,16 @@ class OAuthCallback(OAuthClientMixin, View): if "error" in token: return self.handle_login_failure(token["error"]) # Fetch profile info - raw_info = client.get_profile_info(token) - if raw_info is None: + try: + raw_info = client.get_profile_info(token) + if raw_info is None: + return self.handle_login_failure("Could not retrieve profile.") + except JSONDecodeError as exc: + Event.new( + EventAction.CONFIGURATION_ERROR, + message=f"Failed to JSON-decode profile.", + raw_profile=exc.doc, + ).from_http(self.request) return self.handle_login_failure("Could not retrieve profile.") identifier = self.get_user_id(raw_info) if identifier is None: