[Python] How do I authenticate with HTTP Digest?

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently authenticating with basic, following this tutorial:

    import secrets

    from fastapi import FastAPI, Depends, HTTPException, status
    from fastapi.security import HTTPBasic, HTTPBasicCredentials,

    http_basic = HTTPBasic()

    def authorize_basic(credentials: HTTPBasicCredentials = Depends(http_basic)):
    correct_username = secrets.compare_digest(credentials.username, "test")
    correct_password = secrets.compare_digest(credentials.password, "test")
    if not (correct_username and correct_password):
    raise HTTPException(
    status_code=status.HTTP_401_UNAUTHORIZED,
    detail="Incorrect username or password",
    headers={"WWW-Authenticate": "Basic"},
    )

    @app.get("/auth/", dependencies=[Depends(authorize_basic)])
    def auth():
    return {"success": "true"}


    How do I use HTTPDigest instead?

    Continue reading...

Compartilhe esta Página