Skip to content

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

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/mcp/server/auth/middleware/bearer_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def __init__(
self.provider = provider

async def authenticate(self, conn: HTTPConnection):
auth_header = conn.headers.get("Authorization")
auth_header = conn.headers.get("Authorization") or conn.headers.get(
"authorization"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
)

if not auth_header or not auth_header.startswith("Bearer "):
Copy link
Contributor

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?

return None

Expand Down
Loading