-
Notifications
You must be signed in to change notification settings - Fork 4.1k
WIP: fix: allow JWT auth for views used in Authoring MFE #37093
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
This is only a proof of concept, work still in progress. Fixes: openedx/frontend-app-authoring#1080 Private-ref: https://tasks.opencraft.com/browse/BB-9549
Thanks for the pull request, @samuelallan72! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Update the status of your PRYour PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate. Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
@require_http_methods(("DELETE", "GET", "PUT", "POST", "PATCH")) | ||
@login_required | ||
# @require_http_methods(("DELETE", "GET", "PUT", "POST", "PATCH")) | ||
@view_auth_classes() | ||
@expect_json |
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.
I feel like we can drop the expect_json
decorator here, as django_rest_framework should handle json gracefully. Not sure if we can/should force json-only - I think django_rest_framework will also accept and parse form encoded data too.
@expect_json | ||
@api_view(http_method_names=["DELETE", "GET", "PUT", "POST", "PATCH"]) |
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.
I'm not sure yet if the api_view
decorator makes any changes that would subtly break any assumptions of normal django request handlers (eg. with error handling). Also not sure if we should use the function based decorator here, or go for a class based API view - similar to https://github.com/samuelallan72/edx-platform/blob/efc77256a832e464f6aba3e3a7bef9de1702a539/openedx/core/djangoapps/content_libraries/rest_api/blocks.py#L430-L440 (this code was written in #35765 as part of an API conversion to fix a similar issue)
@transaction.non_atomic_requests | ||
@require_http_methods(("DELETE", "GET", "PUT", "POST", "PATCH")) | ||
@login_required | ||
# @require_http_methods(("DELETE", "GET", "PUT", "POST", "PATCH")) | ||
@view_auth_classes() | ||
@expect_json |
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.
For the existing decorators, I'm not sure yet if they are fully compatible with the DRF api_view
, or if any particular order is required. For example, I discovered that here expect_json
must be before api_view
, otherwise the request crashes with an error about reading the request body more than once.
Description
Avoid authentication errors from MFEs (specifically the Authoring MFE here) in the case where the LMS is logged in, but Studio is not yet authenticated.
Fixes: #1080
TODO:
Supporting information
Private-ref: https://tasks.opencraft.com/browse/BB-9549
Testing instructions
Other information
See also openedx/frontend-app-authoring#1080 (comment) and openedx/frontend-app-authoring#2335 . There may be alternate or better methods of implementing this.