Skip to content
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

Support Fastapi HTTPConnection as well as Request for middleware #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

primal100
Copy link

I would like to use the AuthJWTclass in Fastapi Middleware (such as in Starlette AuthenticationMiddleware in order to set request.user). However in middleware a fastapi.HTTPConnection is provided instead of a fastapi.Request. Request is a subclass of HTTPConnection.

The AuthJWT class has instance checks for Request throughout so will fail if a HTTPConnection is provided.

This PR makes two changes.

  1. Uses HTTPConnection instead of Request in the AuthJWT class. Request will still work as it is a subclass of HTTPConnection so will pass instance checks.
  2. HTTPConnection has no method attribute. So request.method has been changed to request.scopes['method'] which is available for both HTTPConnection and Request.

@sijokun
Copy link
Owner

sijokun commented Apr 11, 2024

As always I saw this only now. Changes sound good, will test them and merge in the next few days.

Thanks for PR!

@sijokun
Copy link
Owner

sijokun commented Apr 22, 2024

Sorry that I forgot about your PR. Can you please add tests with usage in Fastapi Middleware and then I will merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants