Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
FastAPI create auth for all endpoints

I followed this documentation to setup up a single user: https://fastapi.tiangolo.com/advanced/security/http-basic-auth/

But I only get prompted for user/pass for that one end point, "/users/me".

How do I ensure that all endpoints are behind auth?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can configure FastAPI with a set of dependencies that needs to be resolved for any endpoint by giving the paramter directly when creating the FastAPI application (i.e. global dependencies):

security = HTTPBasic()

app = FastAPI(dependencies=[Depends(security)])

If you want some endpoints to be authenticated and some to be unauthenticated, you can create separate instances of APIRouter, then assign required dependencies to the one that require authentication:

unauthenticated_router = APIRouter()
authenticated_router = APIRouter(dependencies=[Depends(security)])

.. and then either include other routers under each (using .include_router) or register endpoints as you'd do with the app object - but instead use your two routers.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda