Home / Class/ HTTPBasic Class — fastapi Architecture

HTTPBasic Class — fastapi Architecture

Architecture documentation for the HTTPBasic class in http.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  4e2b048a_4ece_200c_1c67_a89f28fd47db["HTTPBasic"]
  7b709818_b832_ceea_aedf_a621ca961213["HTTPBase"]
  4e2b048a_4ece_200c_1c67_a89f28fd47db -->|extends| 7b709818_b832_ceea_aedf_a621ca961213
  96278b4c_a391_681f_b974_563be8af72ce["http.py"]
  4e2b048a_4ece_200c_1c67_a89f28fd47db -->|defined in| 96278b4c_a391_681f_b974_563be8af72ce
  43b65f2d_ec05_8f70_3e9c_1ece256be8dc["__init__()"]
  4e2b048a_4ece_200c_1c67_a89f28fd47db -->|method| 43b65f2d_ec05_8f70_3e9c_1ece256be8dc
  ed17ae85_3d39_469e_907e_e29828853a41["make_authenticate_headers()"]
  4e2b048a_4ece_200c_1c67_a89f28fd47db -->|method| ed17ae85_3d39_469e_907e_e29828853a41
  a697d1f6_bd76_670c_2a20_c42790a213a7["__call__()"]
  4e2b048a_4ece_200c_1c67_a89f28fd47db -->|method| a697d1f6_bd76_670c_2a20_c42790a213a7

Relationship Graph

Source Code

fastapi/security/http.py lines 107–221

class HTTPBasic(HTTPBase):
    """
    HTTP Basic authentication.

    Ref: https://datatracker.ietf.org/doc/html/rfc7617

    ## Usage

    Create an instance object and use that object as the dependency in `Depends()`.

    The dependency result will be an `HTTPBasicCredentials` object containing the
    `username` and the `password`.

    Read more about it in the
    [FastAPI docs for HTTP Basic Auth](https://fastapi.tiangolo.com/advanced/security/http-basic-auth/).

    ## Example

    ```python
    from typing import Annotated

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

    app = FastAPI()

    security = HTTPBasic()


    @app.get("/users/me")
    def read_current_user(credentials: Annotated[HTTPBasicCredentials, Depends(security)]):
        return {"username": credentials.username, "password": credentials.password}
    ```
    """

    def __init__(
        self,
        *,
        scheme_name: Annotated[
            Optional[str],
            Doc(
                """
                Security scheme name.

                It will be included in the generated OpenAPI (e.g. visible at `/docs`).
                """
            ),
        ] = None,
        realm: Annotated[
            Optional[str],
            Doc(
                """
                HTTP Basic authentication realm.
                """
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                """
                Security scheme description.

                It will be included in the generated OpenAPI (e.g. visible at `/docs`).
                """
            ),
        ] = None,
        auto_error: Annotated[
            bool,
            Doc(
                """
                By default, if the HTTP Basic authentication is not provided (a
                header), `HTTPBasic` will automatically cancel the request and send the
                client an error.

                If `auto_error` is set to `False`, when the HTTP Basic authentication
                is not available, instead of erroring out, the dependency result will
                be `None`.

                This is useful when you want to have optional authentication.

                It is also useful when you want to have authentication that can be

Domain

Extends

Frequently Asked Questions

What is the HTTPBasic class?
HTTPBasic is a class in the fastapi codebase, defined in fastapi/security/http.py.
Where is HTTPBasic defined?
HTTPBasic is defined in fastapi/security/http.py at line 107.
What does HTTPBasic extend?
HTTPBasic extends HTTPBase.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free