-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Update authentication.py Code Simplification #9502
Conversation
Reduced redundant checks in the authenticate method by combining the conditions for the length of auth. Removed the unnecessary elif in favor of an if to make the code flow clearer
""" | ||
A custom token model may be used, but must have the following properties. | ||
|
||
* key -- The string identifying the token | ||
* user -- The user to which the token belongs | ||
""" |
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.
Why would this need to be removed?
if len(auth) == 1: | ||
msg = _('Invalid token header. No credentials provided.') | ||
raise exceptions.AuthenticationFailed(msg) | ||
elif len(auth) > 2: | ||
msg = _('Invalid token header. Token string should not contain spaces.') | ||
raise exceptions.AuthenticationFailed(msg) |
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.
What happened to these error messages? The idea is to validate the shape of the token header; with your proposed code, an invalid token will go unnoticed.
msg = _('Invalid token header. Token string should not contain invalid characters.') | ||
raise exceptions.AuthenticationFailed(msg) | ||
raise exceptions.AuthenticationFailed( | ||
_('Invalid token header. Token string should not contain invalid characters.') | ||
) |
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.
Why is this change necessary?
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 am closing this PR as not needed for now
Reduced redundant checks in the authenticate method by combining the conditions for the length of auth. Removed the unnecessary elif in favor of an if to make the code flow clearer
Note: Before submitting a code change, please review our contributing guidelines.
Description
Please describe your pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. When linking to an issue, please use
refs #...
in the description of the pull request.