Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!