Browse Source

Align HTTPBasic realm behavior with existing implementation

pull/14662/head
Srikari12 6 months ago
parent
commit
f972f2a927
  1. 9
      fastapi/security/http.py
  2. 2
      tests/test_security_http_basic_optional.py

9
fastapi/security/http.py

@ -298,10 +298,17 @@ class HTTPBearer(HTTPBase):
),
] = True,
):
self.model = HTTPBearerModel(bearerFormat=bearerFormat, description=description)
if realm is None:
raise ValueError(
"HTTP Basic authentication requires a realm as per RFC 7617"
)
self.model = HTTPBaseModel(scheme="basic", description=description)
self.scheme_name = scheme_name or self.__class__.__name__
self.realm = realm
self.auto_error = auto_error
async def __call__(
self, request: Request
) -> Optional[HTTPAuthorizationCredentials]:

2
tests/test_security_http_basic_optional.py

@ -75,3 +75,5 @@ def test_openapi_schema():
"securitySchemes": {"HTTPBasic": {"type": "http", "scheme": "basic"}}
},
}

Loading…
Cancel
Save