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 the latest url as stated in the Microsoft docs #459

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 10 additions & 13 deletions social_core/backends/azuread_b2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
class AzureADB2COAuth2(AzureADOAuth2):
name = 'azuread-b2c-oauth2'

BASE_URL = 'https://login.microsoftonline.com/{tenant_id}'
BASE_URL = 'https://{tenant_name}.b2clogin.com/{tenant_name}.onmicrosoft.com/{policy}'
AUTHORIZATION_URL = '{base_url}/oauth2/v2.0/authorize'
OPENID_CONFIGURATION_URL = '{base_url}/v2.0/.well-known/openid-configuration?p={policy}'
ACCESS_TOKEN_URL = '{base_url}/oauth2/v2.0/token?p={policy}'
JWKS_URL = '{base_url}/discovery/v2.0/keys?p={policy}'
OPENID_CONFIGURATION_URL = '{base_url}/v2.0/.well-known/openid-configuration'
ACCESS_TOKEN_URL = '{base_url}/oauth2/v2.0/token'
JWKS_URL = '{base_url}/discovery/v2.0/keys'
DEFAULT_SCOPE = ['openid', 'email']
EXTRA_DATA = [
('access_token', 'access_token'),
Expand All @@ -72,8 +72,8 @@ class AzureADB2COAuth2(AzureADOAuth2):
]

@property
def tenant_id(self):
return self.setting('TENANT_ID', 'common')
def tenant_name(self):
return self.setting('TENANT_NAME', 'common')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks setup for existing users, are these different, or this is just a different name for the same value?


@property
def policy(self):
Expand All @@ -85,23 +85,20 @@ def policy(self):

@property
def base_url(self):
return self.BASE_URL.format(tenant_id=self.tenant_id)
return self.BASE_URL.format(tenant_name=self.tenant_name, policy=self.policy)

def openid_configuration_url(self):
return self.OPENID_CONFIGURATION_URL.format(base_url=self.base_url,
policy=self.policy)
return self.OPENID_CONFIGURATION_URL.format(base_url=self.base_url)

def authorization_url(self):
# Policy is required, but added later by `auth_extra_arguments()`
return self.AUTHORIZATION_URL.format(base_url=self.base_url)

def access_token_url(self):
return self.ACCESS_TOKEN_URL.format(base_url=self.base_url,
policy=self.policy)
return self.ACCESS_TOKEN_URL.format(base_url=self.base_url)

def jwks_url(self):
return self.JWKS_URL.format(base_url=self.base_url,
policy=self.policy)
return self.JWKS_URL.format(base_url=self.base_url)

def request_access_token(self, *args, **kwargs):
"""
Expand Down
6 changes: 3 additions & 3 deletions social_core/tests/backends/test_azuread_b2c.py
Original file line number Diff line number Diff line change
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://footenant.b2clogin.com/99999999-0000-0000-0000-999999999999/v2.0/',
'name': 'FooBar',
'nbf': AUTH_TIME,
'oid': '11223344-5566-7788-9999-aabbccddeeff',
Expand All @@ -140,14 +140,14 @@ def extra_settings(self):
settings.update({
'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/b2c_1_signin/discovery/v2.0/keys'
keys_body = json.dumps({
'keys': [{
# Dummy public key that pairs with `access_token_body` key:
Expand Down