diff --git a/docker-compose.yml b/docker-compose.yml index 57471b2ab..d9e05a994 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,8 +19,8 @@ services: context: . dockerfile: ./files/tests/Dockerfile args: - - PYTHON_VERSIONS=3.6.12 3.7.9 3.8.7 3.9.1 + - PYTHON_VERSIONS=3.6.12 3.7.16 3.8.16 3.9.16 3.10.10 3.11.2 environment: - - PYTHON_VERSIONS=3.6.12 3.7.9 3.8.7 3.9.1 + - PYTHON_VERSIONS=3.6.12 3.7.16 3.8.16 3.9.16 3.10.10 3.11.2 volumes: - .:/code diff --git a/social_core/backends/azuread_b2c.py b/social_core/backends/azuread_b2c.py index fa2c3edea..63b9d4cde 100644 --- a/social_core/backends/azuread_b2c.py +++ b/social_core/backends/azuread_b2c.py @@ -53,6 +53,7 @@ class AzureADB2COAuth2(AzureADOAuth2): name = "azuread-b2c-oauth2" + BASE_URL = "https://{tenant_name}.{authority_host}/{tenant_name}.onmicrosoft.com" AUTHORIZATION_URL = "{base_url}/oauth2/v2.0/authorize" OPENID_CONFIGURATION_URL = ( "{base_url}/v2.0/.well-known/openid-configuration?p={policy}" @@ -74,8 +75,12 @@ class AzureADB2COAuth2(AzureADOAuth2): ] @property - def tenant_id(self): - return self.setting("TENANT_ID", "common") + def authority_host(self): + return self.setting("AUTHORITY_HOST", "b2clogin.com") + + @property + def tenant_name(self): + return self.setting("TENANT_NAME") @property def policy(self): @@ -87,6 +92,12 @@ def policy(self): ) return policy + @property + def base_url(self): + return self.BASE_URL.format( + tenant_name=self.tenant_name, authority_host=self.authority_host + ) + def openid_configuration_url(self): return self.OPENID_CONFIGURATION_URL.format( base_url=self.base_url, policy=self.policy diff --git a/social_core/tests/backends/test_azuread_b2c.py b/social_core/tests/backends/test_azuread_b2c.py index 5731da578..4a2682e46 100644 --- a/social_core/tests/backends/test_azuread_b2c.py +++ b/social_core/tests/backends/test_azuread_b2c.py @@ -83,7 +83,7 @@ } -class AzureADOAuth2Test(OAuth2Test): +class AzureADB2COAuth2Test(OAuth2Test): AUTH_KEY = "abcdef12-1234-9876-0000-abcdef098765" EXPIRES_IN = 3600 AUTH_TIME = int(time()) @@ -120,7 +120,7 @@ class AzureADOAuth2Test(OAuth2Test): "family_name": "Bar", "given_name": "Foo", "iat": AUTH_TIME, - "iss": "https://login.microsoftonline.com/9a9a9a9a-1111-5555-0000-bc24adfdae00/v2.0/", + "iss": "https://foobar.b2clogin.com/9a9a9a9a-1111-5555-0000-bc24adfdae00/v2.0/", "name": "FooBar", "nbf": AUTH_TIME, "oid": "11223344-5566-7788-9999-aabbccddeeff", @@ -142,7 +142,7 @@ def extra_settings(self): { "SOCIAL_AUTH_" + self.name + "_POLICY": "b2c_1_signin", "SOCIAL_AUTH_" + self.name + "_KEY": self.AUTH_KEY, - "SOCIAL_AUTH_" + self.name + "_TENANT_ID": "footenant.onmicrosoft.com", + "SOCIAL_AUTH_" + self.name + "_TENANT_NAME": "footenant", } ) return settings @@ -150,7 +150,7 @@ def extra_settings(self): def setUp(self): super().setUp() - keys_url = "https://login.microsoftonline.com/footenant.onmicrosoft.com/discovery/v2.0/keys?p=b2c_1_signin" + keys_url = "https://footenant.b2clogin.com/footenant.onmicrosoft.com/discovery/v2.0/keys?p=b2c_1_signin" keys_body = json.dumps( { "keys": [