-
-
Notifications
You must be signed in to change notification settings - Fork 337
Closed
Labels
Description
Hello, I am having difficulty implementing authorization using FastApi and Dependency Injection Framework. I am trying to do something like this:
from fastapi import Depends, APIRouter
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from dependency_injector.wiring import inject, Provide
from services.some_service import SomeService
from containers import Container
router = APIRouter()
security = HTTPBasic()
@router.get("/users/me")
@inject
def read_current_user(
some_service: SomeService = Depends(Provide[Container.some_service]),
credentials: HTTPBasicCredentials = Depends(security)
):
return {"username": credentials.username, "password": credentials.password}
But I am getting an error: AttributeError: 'HTTPBasic' object has no attribute 'provider'
. I tried to add HTTPBasic
to the container and use from there, it fixed the error, but the authorization still didn't work. I am clearly missing something. Is there a template for this? Thanks in advance for your help with this issue!