Skip to content

Commit c091213

Browse files
authored
Merge pull request #233 from mwigh/azuread-v2
Handle scope and also removing resource when VERSION=v2.0
2 parents 27b5813 + 14d25fc commit c091213

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

.github/workflows/testing.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
strategy:
3131
fail-fast: false
3232
matrix:
33-
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10" ]
33+
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
3434
django-version: [ "2.2", "3.0", "3.1", "3.2", "4.0" ]
3535
drf-version: [ "3.10", "3.11", "3.12" ]
3636
exclude:
@@ -57,7 +57,7 @@ jobs:
5757
uses: actions/cache@v2
5858
with:
5959
path: .venv
60-
key: ${{ hashFiles('**/poetry.lock') }}-${{ matrix.python-version }}
60+
key: ${{ hashFiles('**/poetry.lock') }}-${{ matrix.python-version }}-1
6161
- run: poetry env use ${{ matrix.python-version }} && poetry install --no-root
6262
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
6363
- run: |

django_auth_adfs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
Adding imports here will break setup.py
55
"""
66

7-
__version__ = '1.9.5'
7+
__version__ = '1.9.6'

django_auth_adfs/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,11 @@ def build_authorization_endpoint(self, request, disable_sso=None, force_mfa=Fals
337337
"state": redirect_to,
338338
})
339339
if self._mode == "openid_connect":
340-
query["scope"] = "openid"
340+
if settings.VERSION == 'v2.0':
341+
query["scope"] = f"openid api://{settings.RELYING_PARTY_ID}/.default"
342+
query.pop("resource")
343+
else:
344+
query["scope"] = "openid"
341345
if (disable_sso is None and settings.DISABLE_SSO) or disable_sso is True:
342346
query["prompt"] = "login"
343347
if force_mfa:

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = 'django-auth-adfs'
3-
version = "1.9.5" # Remember to also change __init__.py version
3+
version = "1.9.6" # Remember to also change __init__.py version
44
description = 'A Django authentication backend for Microsoft ADFS and AzureAD'
55
authors = ['Joris Beckers <[email protected]>']
66
maintainers = ['Jonas Krüger Svensson <[email protected]>', 'Sondre Lillebø Gundersen <[email protected]>']
@@ -23,7 +23,6 @@ classifiers = [
2323
'License :: OSI Approved :: BSD License',
2424
'Programming Language :: Python',
2525
'Programming Language :: Python :: 3',
26-
'Programming Language :: Python :: 3.6',
2726
'Programming Language :: Python :: 3.7',
2827
'Programming Language :: Python :: 3.8',
2928
'Programming Language :: Python :: 3.9',
@@ -36,7 +35,7 @@ classifiers = [
3635
]
3736

3837
[tool.poetry.dependencies]
39-
python = '^3.6'
38+
python = '^3.7'
4039
django = [
4140
{ version = '^2.2 || ^3', python = '<=3.7' },
4241
{ version = '^2.2 || ^3 || ^4', python = '>=3.8' },

tests/test_authentication.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_oauth_redir_2016(self):
330330
self.assertEqual(qs, qs_expected)
331331

332332
@mock_adfs("azure")
333-
def test_oauth_redir_azure(self):
333+
def test_oauth_redir_azure_version_one(self):
334334
from django_auth_adfs.config import django_settings
335335
settings = deepcopy(django_settings)
336336
del settings.AUTH_ADFS["SERVER"]
@@ -355,6 +355,32 @@ def test_oauth_redir_azure(self):
355355
self.assertEqual(redir.path.rstrip("/"), '/01234567-89ab-cdef-0123-456789abcdef/oauth2/authorize')
356356
self.assertEqual(qs, sq_expected)
357357

358+
@mock_adfs("azure")
359+
def test_oauth_redir_azure_version_two(self):
360+
from django_auth_adfs.config import django_settings
361+
settings = deepcopy(django_settings)
362+
del settings.AUTH_ADFS["SERVER"]
363+
settings.AUTH_ADFS["TENANT_ID"] = "dummy_tenant_id"
364+
settings.AUTH_ADFS["VERSION"] = 'v2.0'
365+
with patch("django_auth_adfs.config.django_settings", settings), \
366+
patch("django_auth_adfs.config.settings", Settings()), \
367+
patch("django_auth_adfs.views.provider_config", ProviderConfig()):
368+
response = self.client.get("/oauth2/login?next=/test/")
369+
self.assertEqual(response.status_code, 302)
370+
redir = urlparse(response["Location"])
371+
qs = parse_qs(redir.query)
372+
sq_expected = {
373+
'scope': ['openid api://your-adfs-RPT-name/.default'],
374+
'client_id': ['your-configured-client-id'],
375+
'state': ['L3Rlc3Qv'],
376+
'response_type': ['code'],
377+
'redirect_uri': ['http://testserver/oauth2/callback']
378+
}
379+
self.assertEqual(redir.scheme, 'https')
380+
self.assertEqual(redir.hostname, 'login.microsoftonline.com')
381+
self.assertEqual(redir.path.rstrip("/"), '/01234567-89ab-cdef-0123-456789abcdef/oauth2/authorize')
382+
self.assertEqual(qs, sq_expected)
383+
358384
@mock_adfs("2016")
359385
def test_inactive_user(self):
360386
user = User.objects.create(**{

0 commit comments

Comments
 (0)