Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -11,6 +11,7 @@ Abhishek Patel
Adam Johnson
Adam Zahradník
Adheeth P Praveen
Aibek Prenov
Alan Crosswell
Alan Rominger
Alejandro Mantecon Guillen
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* #1584 Fix IDP container in docker compose environment could not find templates and static files.
* #1562 Fix: Handle AttributeError in IntrospectTokenView
* #1583 Fix: Missing pt_BR translations
* #1597 Fix: TypeError at /s/auth/o/token/
<!--
### Security
-->
Expand Down
6 changes: 5 additions & 1 deletion oauth2_provider/oauth2_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,16 @@ def get_id_token_dictionary(self, token, token_handler, request):
claims = self.get_oidc_claims(token, token_handler, request)

expiration_time = timezone.now() + timedelta(seconds=oauth2_settings.ID_TOKEN_EXPIRE_SECONDS)
if request.user.last_login:
auth_time = int(dateformat.format(request.user.last_login, "U"))
else:
auth_time = int(timezone.now().timestamp())
# Required ID Token claims
claims.update(
**{
"iss": self.get_oidc_issuer_endpoint(request),
"exp": int(dateformat.format(expiration_time, "U")),
"auth_time": int(dateformat.format(request.user.last_login, "U")),
"auth_time": auth_time,
"jti": str(uuid.uuid4()),
Comment on lines 899 to 910
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

int(timezone.now().timestamp()) can differ from Django’s dateformat.format(..., 'U') behavior (notably when USE_TZ=False, where .timestamp() on naive datetimes is interpreted in local time). For consistency with the existing codepath and Django’s formatting semantics, compute the fallback using the same mechanism as the non-null branch (i.e., format timezone.now() with 'U').

Copilot uses AI. Check for mistakes.
}
)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_oauth2_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def always_invalid_token():
class TestOAuth2Validator(TransactionTestCase):
def setUp(self):
self.user = UserModel.objects.create_user("user", "test@example.com", "123456")
self.user.last_login = None
self.user.save()
Comment on lines +63 to +64
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

Setting last_login = None in setUp() adds an extra DB write for every test in this class and makes the entire class depend on a special user state (even in tests unrelated to OIDC auth_time). Prefer moving this setup into the specific test(s) that exercise the last_login is None path, or create a dedicated user within that test to keep unrelated tests isolated and faster.

Suggested change
self.user.last_login = None
self.user.save()

Copilot uses AI. Check for mistakes.
self.request = mock.MagicMock(wraps=Request)
self.request.user = self.user
self.request.grant_type = "not client"
Expand Down
Loading