diff --git a/authentik/sources/oauth/tests/test_type_azure_ad.py b/authentik/sources/oauth/tests/test_type_azure_ad.py index da2562483..ff9b078f9 100644 --- a/authentik/sources/oauth/tests/test_type_azure_ad.py +++ b/authentik/sources/oauth/tests/test_type_azure_ad.py @@ -41,6 +41,6 @@ class TestTypeAzureAD(TestCase): def test_enroll_context(self): """Test azure_ad Enrollment context""" ak_context = AzureADOAuthCallback().get_user_enroll_context(AAD_USER) - self.assertEqual(ak_context["username"], AAD_USER["displayName"]) + self.assertEqual(ak_context["username"], AAD_USER["userPrincipalName"]) self.assertEqual(ak_context["email"], AAD_USER["mail"]) self.assertEqual(ak_context["name"], AAD_USER["displayName"]) diff --git a/authentik/sources/oauth/types/azure_ad.py b/authentik/sources/oauth/types/azure_ad.py index 618494c57..d7c5dc49c 100644 --- a/authentik/sources/oauth/types/azure_ad.py +++ b/authentik/sources/oauth/types/azure_ad.py @@ -31,7 +31,7 @@ class AzureADOAuthCallback(OAuthCallback): ) -> dict[str, Any]: mail = info.get("mail", None) or info.get("otherMails", [None])[0] return { - "username": info.get("displayName"), + "username": info.get("userPrincipalName"), "email": mail, "name": info.get("displayName"), }