Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Azure AD B2C base URL to match updated endpoints #777

Merged
merged 4 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 13 additions & 2 deletions social_core/backends/azuread_b2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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):
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions social_core/tests/backends/test_azuread_b2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}


class AzureADOAuth2Test(OAuth2Test):
class AzureADB2COAuth2Test(OAuth2Test):
AUTH_KEY = "abcdef12-1234-9876-0000-abcdef098765"
EXPIRES_IN = 3600
AUTH_TIME = int(time())
Expand Down Expand Up @@ -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",
Expand All @@ -142,15 +142,15 @@ 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

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": [
Expand Down