From a8998a6356c703b2e49ea9e3bfe865f3e2224815 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 20 Apr 2021 17:27:52 +0200 Subject: [PATCH] sources/oauth: handle error in auzre_ad when ID Can't be extracted Signed-off-by: Jens Langhammer --- authentik/sources/oauth/types/azure_ad.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/authentik/sources/oauth/types/azure_ad.py b/authentik/sources/oauth/types/azure_ad.py index 1e23516d4..fbd81f08f 100644 --- a/authentik/sources/oauth/types/azure_ad.py +++ b/authentik/sources/oauth/types/azure_ad.py @@ -1,5 +1,5 @@ """AzureAD OAuth2 Views""" -from typing import Any +from typing import Any, Optional from uuid import UUID from authentik.sources.oauth.models import OAuthSource, UserOAuthSourceConnection @@ -10,8 +10,11 @@ from authentik.sources.oauth.views.callback import OAuthCallback class AzureADOAuthCallback(OAuthCallback): """AzureAD OAuth2 Callback""" - def get_user_id(self, source: OAuthSource, info: dict[str, Any]) -> str: - return str(UUID(info.get("objectId")).int) + def get_user_id(self, source: OAuthSource, info: dict[str, Any]) -> Optional[str]: + try: + return str(UUID(info.get("objectId")).int) + except TypeError: + return None def get_user_enroll_context( self,