This repository was archived by the owner on Oct 22, 2025. It is now read-only.
forked from openedx/auth-backends
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: enhance get_user_if_exists pipeline function with debugging capabilities #1
Merged
Akanshu-2u
merged 21 commits into
edx:master
from
Akanshu-2u:akanshu/bug-in-third-party-authentication-email-and-name-update
Sep 3, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d2dbaf8
feat: add DEBUG_GET_USER_IF_EXISTS toggle and enhance get_user_if_exi…
Akanshu-2u c3dd58f
fix: remove redundant set_custom_attribute patch and unused mock_Set_…
Akanshu-2u 3dca82d
feat: introduce IGNORE_LOGGED_IN_USER_ON_MISMATCH toggle and updated …
Akanshu-2u 8615084
fix: improve logging message for username mismatch in get_user_if_exi…
Akanshu-2u 3bc63ef
fix: update logging message for username mismatch in get_user_if_exis…
Akanshu-2u 19e06a9
docs: Update CHANGELOG.rst
Akanshu-2u fb5db54
feat: enhance get_user_if_exists function with toggle tracking and re…
Akanshu-2u b466482
fix: added ddt module inrequirements/test.in
Akanshu-2u 83a11d9
fix: added responses module in test.in
Akanshu-2u fc85284
feat: added relevant comments in test and package fix
Akanshu-2u 65c30a6
fix: updated use of response and typing_extension with social-core ve…
Akanshu-2u 5c1717d
refactor: update test descriptions for clarity and adjust responses r…
Akanshu-2u c87ef89
refactor: enhance mock assertions and improve test descriptions for c…
Akanshu-2u 08b79c4
refactor: add comments to test cases for toggle and clarify expected …
Akanshu-2u e59b787
refactor: simplify docstring formatting and enhance test cases for us…
Akanshu-2u 40ce368
refactor: improve test descriptions for user existence scenarios and …
Akanshu-2u 989ae11
refactor: update test descriptions for clarity in user existence scen…
Akanshu-2u 218889e
refactor: improve test descriptions and formatting for clarity in use…
Akanshu-2u 660866f
refactor: flatten the details dictionary
Akanshu-2u 9305b4c
refactor: update CHANGELOG and enhance user authentication pipeline w…
Akanshu-2u fb0ca7e
fix: Update auth_backends/pipeline.py comment
Akanshu-2u File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| from calendar import timegm | ||
|
|
||
| import jwt | ||
| import responses | ||
| import six | ||
| from Cryptodome.PublicKey import RSA | ||
| from django.core.cache import cache | ||
|
|
@@ -37,10 +38,13 @@ def set_social_auth_setting(self, setting_name, value): | |
| # does not rely on Django settings. | ||
| self.strategy.set_settings({f'SOCIAL_AUTH_{backend_name}_{setting_name}': value}) | ||
|
|
||
| def access_token_body(self, request, _url, headers): | ||
| def access_token_body(self, request): | ||
| """ Generates a response from the provider's access token endpoint. """ | ||
| # The backend should always request JWT access tokens, not Bearer. | ||
| body = six.moves.urllib.parse.parse_qs(request.body.decode('utf8')) | ||
| body_content = request.body | ||
| if isinstance(body_content, bytes): | ||
| body_content = body_content.decode('utf8') | ||
| body = six.moves.urllib.parse.parse_qs(body_content) | ||
| self.assertEqual(body['token_type'], ['jwt']) | ||
|
|
||
| expires_in = 3600 | ||
|
|
@@ -51,7 +55,16 @@ def access_token_body(self, request, _url, headers): | |
| 'expires_in': expires_in, | ||
| 'access_token': access_token | ||
| }) | ||
| return 200, headers, body | ||
| return (200, {}, body) | ||
|
||
|
|
||
| def pre_complete_callback(self, start_url): | ||
| """ Override to properly set up the access token response with callback. """ | ||
| responses.add_callback( | ||
| responses.POST, | ||
| url=self.backend.access_token_url(), | ||
| callback=self.access_token_body, | ||
| content_type="application/json", | ||
| ) | ||
|
|
||
| def create_jwt_access_token(self, expires_in=3600, issuer=None, key=None, alg='RS512'): | ||
| """ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The empty pass statement with removed comment makes the control flow unclear. Consider adding a brief comment explaining that this exception is expected when no user exists.