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

Returning a 401 response #1632

Open
basvandriel opened this issue Feb 7, 2022 · 1 comment
Open

Returning a 401 response #1632

basvandriel opened this issue Feb 7, 2022 · 1 comment

Comments

@basvandriel
Copy link
Contributor

basvandriel commented Feb 7, 2022

In addition too #1579 and this solution for Apollo Server; maybe it would be a handy feature too incorporate a 401 status error when writing auth middleware?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@henrjk
Copy link

henrjk commented Feb 9, 2022

I have been looking at converting some existing code from starlette/graphene/fastapi to strawberry/fastapi.
I made great progress quickly and liked what I found. However I now hit this issue where the apps expect to get a 401 Unauthorized HTTP response, if the correct authorization header is missing. Here is our existing code which works like this (slightly shortened):

from fastapi import APIRouter, FastAPI, Request
from starlette.graphql import GraphQLApp

app = FastAPI()
router = APIRouter()

@router.api_route("/graphql", methods=["GET", "POST"])
async def _route_with_auth(request: Request):
    authenticate(request)  
    # ... authenticate() raises a HttpException(status_code=401) if the authorization header is not correct 
    return await GraphQLApp(schema=get_schema()).handle_graphql(
        request=request)
app.include_router(router, dependencies=[])

With strawberry I struggled for some time now and did not manage to get this working.
It would be very welcome if this could be supported!
Perhaps there is a workaround which I missed?

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

No branches or pull requests

2 participants