Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Spencer Carroll
Dulmandakh Sukhbaatar
Will Beaufoy
Rustem Saiargaliev
Jadiel Teófilo
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
* #915 Add optional OpenID Connect support.
### Fixed
* #524 Restrict usage of timezone aware expire dates to Django projects with USE_TZ set to True.

## [1.4.1]

Expand Down
9 changes: 9 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,12 @@ OIDC_TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED
Default: ``["client_secret_post", "client_secret_basic"]``

The authentication methods that are advertised to be supported by this server.


Settings imported from Django project
--------------------------

USE_TZ
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Used to determine whether or not to make token expire dates timezone aware.
2 changes: 1 addition & 1 deletion oauth2_provider/oauth2_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def _get_token_from_authentication_server(
expires = max_caching_time

scope = content.get("scope", "")
expires = make_aware(expires)
expires = make_aware(expires) if settings.USE_TZ else expires

access_token, _created = AccessToken.objects.update_or_create(
token=token,
Expand Down
21 changes: 21 additions & 0 deletions tests/test_introspection_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime

import pytest
from django.conf import settings
from django.conf.urls import include
from django.contrib.auth import get_user_model
from django.http import HttpResponse
Expand All @@ -12,6 +13,7 @@

from oauth2_provider.models import get_access_token_model, get_application_model
from oauth2_provider.oauth2_validators import OAuth2Validator
from oauth2_provider.settings import oauth2_settings
from oauth2_provider.views import ScopedProtectedResourceView

from . import presets
Expand Down Expand Up @@ -154,6 +156,25 @@ def test_get_token_from_authentication_server_existing_token(self, mock_get):
self.assertEqual(token.user.username, "foo_user")
self.assertEqual(token.scope, "read write dolphin")

@mock.patch("requests.post", side_effect=mocked_requests_post)
def test_get_token_from_authentication_server_expires_timezone(self, mock_get):
"""
Test method _get_token_from_authentication_server for projects with USE_TZ False
"""
settings_use_tz_backup = settings.USE_TZ
settings.USE_TZ = False
try:
self.validator._get_token_from_authentication_server(
"foo",
oauth2_settings.RESOURCE_SERVER_INTROSPECTION_URL,
oauth2_settings.RESOURCE_SERVER_AUTH_TOKEN,
oauth2_settings.RESOURCE_SERVER_INTROSPECTION_CREDENTIALS,
)
except ValueError as exception:
self.fail(str(exception))
finally:
settings.USE_TZ = settings_use_tz_backup

@mock.patch("requests.post", side_effect=mocked_requests_post)
def test_validate_bearer_token(self, mock_get):
"""
Expand Down