mirror of https://github.com/tiangolo/fastapi.git
🐛 Fix HTTP Bearer security auto-error (#282)
This commit is contained in:
parent
d61f5e4b55
commit
d262f6e929
|
|
@ -112,10 +112,13 @@ class HTTPBearer(HTTPBase):
|
|||
else:
|
||||
return None
|
||||
if scheme.lower() != "bearer":
|
||||
raise HTTPException(
|
||||
status_code=HTTP_403_FORBIDDEN,
|
||||
detail="Invalid authentication credentials",
|
||||
)
|
||||
if self.auto_error:
|
||||
raise HTTPException(
|
||||
status_code=HTTP_403_FORBIDDEN,
|
||||
detail="Invalid authentication credentials",
|
||||
)
|
||||
else:
|
||||
return None
|
||||
return HTTPAuthorizationCredentials(scheme=scheme, credentials=credentials)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -64,5 +64,5 @@ def test_security_http_bearer_no_credentials():
|
|||
|
||||
def test_security_http_bearer_incorrect_scheme_credentials():
|
||||
response = client.get("/users/me", headers={"Authorization": "Basic notreally"})
|
||||
assert response.status_code == 403
|
||||
assert response.json() == {"detail": "Invalid authentication credentials"}
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"msg": "Create an account first"}
|
||||
|
|
|
|||
Loading…
Reference in New Issue