Skip to content

Problems with using Depends FastApi method without Provide in wired module #330

@Lojka-oops

Description

@Lojka-oops

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!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions