-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat: add more authentication information to swagger #35674
feat: add more authentication information to swagger #35674
Conversation
this is work in progress FIXES: APER-3554
* updates the `docs-settings` to make the generated swagger `securityDefinitions` include both JWT and CSRF methods, as well as basic. A few linter fixes happened as a side effect. * Put in wordier descriptions for all three, since we don't have great shared documentation about authn/authz. * Added CSRF to `login_session`, which also serves as a proof of concept for other endpoits * Also regenerated the swagger doc, which picked up some extra changes. Generated swagger now has help and allows extra auth methods so some preveiously unusable endpoints can be hit. FIXES: APER-3554
Fixed capitalization error, and ran the linter which reformatted a lot of the file, because github actions really didn't like some lint errors.
@@ -62,17 +65,17 @@ | |||
log = logging.getLogger("edx.student") | |||
AUDIT_LOG = logging.getLogger("audit") | |||
USER_MODEL = get_user_model() | |||
PASSWORD_RESET_INITIATED = 'edx.user.passwordreset.initiated' |
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 apologize for mixing reformatter auto fixes with actual changes in a single PR. Assume everything in this file except the blocks that I am flagging with particular comments are just automatic fixes to make the linter happier.
from drf_yasg import openapi | ||
from drf_yasg.utils import swagger_auto_schema | ||
from edx_django_utils.monitoring import set_custom_attribute | ||
from eventtracking import tracker | ||
from openedx_events.learning.data import UserData, UserPersonalData | ||
from openedx_events.learning.signals import SESSION_LOGIN_COMPLETED | ||
from openedx_filters.learning.filters import StudentLoginRequested | ||
from rest_framework import status |
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.
these lines are a real change, not just formatting.
@swagger_auto_schema( | ||
request_body=login_user_schema, | ||
responses=login_user_responses, | ||
security=[ | ||
{"csrf": []}, | ||
], | ||
) | ||
@method_decorator(csrf_protect) | ||
def post(self, request, api_version): | ||
"""Log in a user. | ||
|
||
See `login_user` for details. | ||
|
||
Example Usage: | ||
|
||
POST /api/user/v1/login_session | ||
with POST params `email`, `password`. | ||
|
||
200 {'success': true} | ||
""" | ||
POST /user/{api_version}/account/login_session/ | ||
|
||
Returns 200 on success, and a detailed error message otherwise. |
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.
these changes are real, not just formatter.
login_user_schema = openapi.Schema( | ||
type=openapi.TYPE_OBJECT, | ||
properties={ | ||
"email": openapi.Schema(type=openapi.TYPE_STRING), | ||
"password": openapi.Schema(type=openapi.TYPE_STRING), | ||
}, | ||
) | ||
|
||
login_user_return_schema = openapi.Schema( | ||
type=openapi.TYPE_OBJECT, | ||
properties={ | ||
"success": openapi.Schema(type=openapi.TYPE_BOOLEAN), | ||
"value": openapi.Schema(type=openapi.TYPE_STRING), | ||
"error_code": openapi.Schema(type=openapi.TYPE_STRING), | ||
}, | ||
) |
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.
these changes are real, not just formatter.
login_user_responses = { | ||
status.HTTP_200_OK: login_user_return_schema, | ||
status.HTTP_400_BAD_REQUEST: login_user_return_schema, | ||
status.HTTP_403_FORBIDDEN: login_user_return_schema, | ||
} | ||
|
||
@method_decorator(ensure_csrf_cookie) |
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.
these changes are real, not just formatter.
@@ -6788,6 +6826,59 @@ paths: | |||
in: path | |||
required: true | |||
type: string | |||
/mobile/{api_version}/notifications/create-token/: |
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.
these are unrelated changes, clearly the documents haven't been regenerated since these endpoints were created.
'token_type': 'jwt' | ||
``` | ||
|
||
Your JWT will be returned in the response as `access_token`. Prefix with `JWT ` in your header. |
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.
is the space in JWT
intentional? My assumption by reading this would be to add this to my header:
JWT {access token string}
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.
yup, that's correct.
Everything looks good to me! |
…user_api-api-docs
the automatic reformatting broke some of the lint amnesty, so I undid the automatic reformatting on those lines in particular.
2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production. |
2U Release Notice: This PR has been deployed to the edX production environment. |
Description
docs-settings
to make the generated swaggersecurityDefinitions
include both JWT and CSRF methods, as well as basic. A few linter fixes happened as a side effect.login_session
, which also serves as a proof of concept for other endpointsGenerated swagger now has help and allows extra auth methods so some preveiously unusable endpoints can be hit.
Testing instructions
make swagger
workslms-openapi.yml
into any OpenAPI validator or preview tool. Online tools are available at https://swagger.io/, and most IDEs have validating plugins.login_session
Images
general authentication modal
login_session
authentication modalFIXES: APER-3554