Skip to content

Commit 84c3a41

Browse files
committed
Add changelog, extra test, bump version, default to None
1 parent b938c27 commit 84c3a41

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
`1.9.0`_ - 2021-08-27
5+
---------------------
6+
7+
**Features**
8+
9+
* Add ``GUEST_USERNAME_CLAIM``, a setting that allow you to use a different username claim for guest users. @JonasKs and @Seykotron #166
10+
11+
412
`1.8.1`_ - 2021-08-27
513
---------------------
614

@@ -261,6 +269,7 @@ Changelog
261269

262270
* Initial release
263271

272+
.. _1.9.0: https://github.com/snok/django-auth-adfs/compare/1.8.1...1.9.0
264273
.. _1.8.1: https://github.com/snok/django-auth-adfs/compare/1.8.0...1.8.1
265274
.. _1.8.0: https://github.com/snok/django-auth-adfs/compare/1.7.0...1.8.0
266275
.. _1.7.0: https://github.com/snok/django-auth-adfs/compare/1.6.1...1.7.0

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.8.1'
7+
__version__ = '1.9.0'

django_auth_adfs/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self):
7070
self.TENANT_ID = None # Required
7171
self.TIMEOUT = 5
7272
self.USERNAME_CLAIM = "winaccountname"
73-
self.GUEST_USERNAME_CLAIM = "email"
73+
self.GUEST_USERNAME_CLAIM = None
7474
self.JWT_LEEWAY = 0
7575
self.CUSTOM_FAILED_RESPONSE_VIEW = lambda request, error_message, status: render(
7676
request, 'django_auth_adfs/login_failed.html', {'error_message': error_message}, status=status

docs/settings_ref.rst

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,25 @@ example
262262
The group doesn't need to exist in Django for this to work. This will work as long as it's in the groups claim
263263
in the access token.
264264

265+
GUEST_USERNAME_CLAIM
266+
--------------------
267+
* **Default**: ``None``
268+
* **Type**: ``string``
269+
270+
When these criteria are met:
271+
272+
1. A ``guest_username_claim`` is configured
273+
2. Token claims do not have the configured ``settings.USERNAME_CLAIM`` in it
274+
3. The ``settings.BLOCK_GUEST_USERS`` is set to ``False``
275+
4. The claims ``tid`` does not match ``settings.TENANT_ID``
276+
277+
Then, the ``GUEST_USERNAME_CLAIM`` can be used to populate a username, when the ``USERNAME_CLAIM`` cannot be found in
278+
the claims.
279+
280+
This can be useful when you want to use ``upn`` as a username claim for your own users,
281+
but some guest users (such as normal outlook users) don't have that claim.
282+
283+
265284
LOGIN_EXEMPT_URLS
266285
-----------------
267286
* **Default**: ``None``
@@ -423,13 +442,13 @@ The value of the claim must be a unique value. No 2 users should ever have the s
423442
.. NOTE::
424443
You can find the short name for the claims you configure in the ADFS management console underneath
425444
**ADFS** ➜ **Service** ➜ **Claim Descriptions**
426-
427-
445+
446+
428447
.. _version_setting:
429448

430449
VERSION
431450
--------------
432-
* **Default**: ``v1.0``
451+
* **Default**: ``v1.0``
433452
* **Type**: ``string``
434453

435454
Version of the Azure Active Directory endpoint version. By default it is set to ``v1.0``. At the time of writing this documentation, it can also be set to ``v2.0``. For new projects, ``v2.0`` is recommended. ``v1.0`` is kept as a default for backwards compatibility.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = 'django-auth-adfs'
3-
version = '1.8.1' # Remember to also change __init__.py version
3+
version = '1.9.0' # 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]>']

tests/test_drf_integration.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ def test_access_token_azure_guest_but_no_upn(self):
115115
user, token = self.drf_auth_class.authenticate(request)
116116
self.assertEqual(user.username, "[email protected]")
117117

118+
@mock_adfs("azure")
119+
def test_access_token_azure_guest_but_no_upn_but_no_guest_username_claim(self):
120+
access_token_header = "Bearer {}".format(self.access_token_azure_guest_no_upn)
121+
request = RequestFactory().get('/api', HTTP_AUTHORIZATION=access_token_header)
122+
from django_auth_adfs.config import django_settings
123+
settings = deepcopy(django_settings)
124+
del settings.AUTH_ADFS["SERVER"]
125+
settings.AUTH_ADFS["TENANT_ID"] = "dummy_tenant_id"
126+
settings.AUTH_ADFS["GUEST_USERNAME_CLAIM"] = None # <--- Set to None, should not be validated as OK
127+
settings.AUTH_ADFS["BLOCK_GUEST_USERS"] = False
128+
with patch("django_auth_adfs.config.django_settings", settings):
129+
with patch('django_auth_adfs.backend.settings', Settings()):
130+
with patch("django_auth_adfs.config.settings", Settings()):
131+
with patch("django_auth_adfs.backend.provider_config", ProviderConfig()):
132+
with self.assertRaises(exceptions.AuthenticationFailed):
133+
self.drf_auth_class.authenticate(request)
134+
118135
@mock_adfs("2012")
119136
def test_access_token_exceptions(self):
120137
access_token_header = "Bearer non-existing-token"

0 commit comments

Comments
 (0)