-
Notifications
You must be signed in to change notification settings - Fork 44
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: ✨ update auth middlewares to allow other auth middlewares #469
base: master
Are you sure you want to change the base?
feat: ✨ update auth middlewares to allow other auth middlewares #469
Conversation
"""Custom Authentication Middleware to attempt logging in with a securely generated | ||
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.
"""Custom Authentication Middleware to attempt logging in with a securely generated | |
token | |
"""Custom Authentication Middleware to attempt logging in with | |
a securely generated token |
Can we break the text differently? Break before the phrase
However, if user is logged in when the exception occurred, it is a connection | ||
failure. Therefore, always go to account settings page or equivalent |
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.
However, if user is logged in when the exception occurred, it is a connection | |
failure. Therefore, always go to account settings page or equivalent | |
However, if user is logged in when the exception occurred, | |
it is a connection failure. | |
Therefore, always go to account settings page or equivalent |
Let's break the text differently. New sentence on new line...
@@ -95,10 +100,10 @@ def set_random_password(user, password_length=16): | |||
|
|||
def email_to_username_hash(email): | |||
"""Convert emails to hashed versions where we store them in the username field | |||
We can't just store them directly, or we'd be limited to Django's username <= 30 chars limit, | |||
which is really too small for arbitrary emails | |||
We can't just store them directly, or we'd be limited to Django's username <= 30 |
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.
please revert, this is breaking docstrings in the middle of the thought/phrase, and makes the docstring harder to understand.
@@ -175,7 +180,7 @@ def get_user_by_email(email): | |||
) | |||
except UserModel.MultipleObjectsReturned: | |||
user = None | |||
request = get_current_request() | |||
request = get_current_request() # noqa: F841 |
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 don't think F841 is the right one. Why?
I think below needs to get updated to:
rollbar.report_exc_info(request=request)
?
Let's double check against other places.
except: | ||
request = get_current_request() | ||
except Exception: | ||
request = get_current_request() # noqa: F841 |
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.
same, change below to rollbar.report_exc_info(request=request)
@@ -304,7 +309,7 @@ def get_user_email(user, email, is_confirmed=True): | |||
return user_email | |||
|
|||
|
|||
def associate_user_email( | |||
def associate_user_email( # noqa: C901 |
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.
else: | ||
# No authentication token provided via available methods | ||
token = None | ||
# and give a chance for other auth middlewares to work |
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.
# and give a chance for other auth middlewares to work | |
# give a chance for other auth middlewares to work |
# unexpected authorization value | ||
token = None | ||
auth_user = authenticate(request=request, token=token) | ||
|
||
elif 'token' in request.GET: | ||
# implicit authenication token using URL params |
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.
# implicit authenication token using URL params | |
# implicit authentication token using URL params |
Description
The main purpose of this PR is to give room to custom authentication middlewares in the projects.
The middlewares were cutting off the execution and giving forbidden errors other than the
Bearer
andBasic
auth token types.Also getting the
token_type
andtoken
fromHTTP_AUTHORIZATION
is made a utility function to keep the code DRY.