-
Notifications
You must be signed in to change notification settings - Fork 823
Fix TypeError at /o/token/ #1597
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@aibaq this is a great start. to help me understand the issue a bit more, in what scenario did you encounter this issue? I would expect that a user would have logged in at least once by the time get_id_token_dictionary was called. I'd like to understand how this was occurring to both correct my expectations and ensure there isn't a bug somewhere else that is allow a token to be generated for a user that isn't authenticated. It also looks like there is a code path that is uncovered that will need to be tested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request fixes a TypeError that occurs at the /o/token/ endpoint when using OIDC and the Django User's last_login field is null. The fix adds a null check for last_login and provides a fallback value using the current timestamp.
- Added null safety check for
request.user.last_loginbefore accessing it - Set
timezone.now().timestamp()as fallback whenlast_loginis null - Added test case to verify the fix works with null
last_loginvalues
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| oauth2_provider/oauth2_validators.py | Added null check for last_login and fallback to current timestamp |
| tests/test_oauth2_validators.py | Added test setup to simulate user with null last_login |
| CHANGELOG.md | Added entry for the TypeError fix |
| AUTHORS | Added contributor name |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
@aibaq We won't be able to close this without the test coverage and details so we can reproduce the bug. |
|
For context, we recently hit the same error after upgrading oauthlib from 3.2 to 3.3. The "id_token" is now included in refresh token responses when the the However, it's unclear for me how this should behave for users who interact only with OAuth applications. For these users, their |
Fixes #
Description of the Change
Django User's last_login field is nullable, so
/o/token/endpoint raises TypeError when last_login is null when using oidcThis fix sets timezone.now() as a default value for auth_time
Checklist
CHANGELOG.mdupdated (only for user relevant changes)AUTHORS