MCPcopy
hub / github.com/fastapi/fastapi / HTTPBasic

Class HTTPBasic

fastapi/security/http.py:105–219  ·  view source on GitHub ↗

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 `passwo

Source from the content-addressed store, hash-verified

103
104
105class HTTPBasic(HTTPBase):
106 """
107 HTTP Basic authentication.
108
109 Ref: https://datatracker.ietf.org/doc/html/rfc7617
110
111 ## Usage
112
113 Create an instance object and use that object as the dependency in `Depends()`.
114
115 The dependency result will be an `HTTPBasicCredentials` object containing the
116 `username` and the `password`.
117
118 Read more about it in the
119 [FastAPI docs for HTTP Basic Auth](https://fastapi.tiangolo.com/advanced/security/http-basic-auth/).
120
121 ## Example
122
123 ```python
124 from typing import Annotated
125
126 from fastapi import Depends, FastAPI
127 from fastapi.security import HTTPBasic, HTTPBasicCredentials
128
129 app = FastAPI()
130
131 security = HTTPBasic()
132
133
134 @app.get("/users/me")
135 def read_current_user(credentials: Annotated[HTTPBasicCredentials, Depends(security)]):
136 return {"username": credentials.username, "password": credentials.password}
137 ```
138 """
139
140 def __init__(
141 self,
142 *,
143 scheme_name: Annotated[
144 str | None,
145 Doc(
146 """
147 Security scheme name.
148
149 It will be included in the generated OpenAPI (e.g. visible at `/docs`).
150 """
151 ),
152 ] = None,
153 realm: Annotated[
154 str | None,
155 Doc(
156 """
157 HTTP Basic authentication realm.
158 """
159 ),
160 ] = None,
161 description: Annotated[
162 str | None,

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…