From 44f4e7aa640cc4b5a229c748897590ef1fdd94fb Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Thu, 22 Aug 2024 20:27:01 +0200 Subject: [PATCH] Add AzureADOauth2 backend using the v2.0 API. AzureADOAuth2 uses the v1.0 API which doesn't support personal accounts. Updating the endpoints used by the original class may break backward compatibility, so add this as just an additional subclass. --- social_core/backends/azuread.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/social_core/backends/azuread.py b/social_core/backends/azuread.py index 837d2c54..29db25b5 100644 --- a/social_core/backends/azuread.py +++ b/social_core/backends/azuread.py @@ -145,3 +145,14 @@ def get_auth_token(self, user_id): new_token_response = self.refresh_token(token=access_token) access_token = new_token_response["access_token"] return access_token + + +class AzureADOAuth2V2(AzureADOAuth2): + """Version of the AzureADOAuth2 backend that uses the v2.0 API endpoints, + supporting users with personal Microsoft accounts, if the app settings + allow them.""" + + name = "azuread-oauth2-v2" + AUTHORIZATION_URL = "{base_url}/oauth2/v2.0/authorize" + ACCESS_TOKEN_URL = "{base_url}/oauth2/v2.0/token" + DEFAULT_SCOPE = ["User.Read profile openid email"]