sources/oauth: handle error in auzre_ad when ID Can't be extracted

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-20 17:27:52 +02:00
parent dc75d7b7f0
commit a8998a6356
1 changed files with 6 additions and 3 deletions

View File

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