-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix the issue of get Authorization header fails during bearer auth #637
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
Fix the issue of get Authorization header fails during bearer auth #637
Conversation
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.
Thanks for addressing header case sensitivity, a few suggestions:
- improve the check for case insensitive handling
- the "Bearer" prefix should also be checked case-insensitively
- add tests to verify the fix and prevent regression
auth_header = conn.headers.get("Authorization") or conn.headers.get( | ||
"authorization" | ||
) |
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.
auth_header = conn.headers.get("Authorization") or conn.headers.get( | |
"authorization" | |
) | |
auth_header = next( | |
(conn.headers.get(key) for key in conn.headers if key.lower() == "authorization"), | |
None | |
) |
auth_header = conn.headers.get("Authorization") | ||
auth_header = conn.headers.get("Authorization") or conn.headers.get( | ||
"authorization" | ||
) | ||
if not auth_header or not auth_header.startswith("Bearer "): |
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.
would Bearer
have the same issue?
@ihrpr thanks for your suggestion. all of the above have been updated.Please review them again. |
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.
thank you
The bearer auth retrieves the Authorization from the headers, but the HTTPConnection.headers uses lowercase authorization, resulting in authentication failure.