Browse Source

Merge 11a6a4cea7 into 8032e21418

pull/5332/merge
Pieter Ennes 2 days ago
committed by GitHub
parent
commit
ea412922fd
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      fastapi/security/open_id_connect_url.py
  2. 3
      tests/test_security_openid_connect.py
  3. 3
      tests/test_security_openid_connect_description.py

6
fastapi/security/open_id_connect_url.py

@ -4,7 +4,7 @@ from fastapi.openapi.models import OpenIdConnect as OpenIdConnectModel
from fastapi.security.base import SecurityBase
from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.status import HTTP_403_FORBIDDEN
from starlette.status import HTTP_401_UNAUTHORIZED
from typing_extensions import Annotated, Doc
@ -77,7 +77,9 @@ class OpenIdConnect(SecurityBase):
if not authorization:
if self.auto_error:
raise HTTPException(
status_code=HTTP_403_FORBIDDEN, detail="Not authenticated"
status_code=HTTP_401_UNAUTHORIZED,
detail="Not authenticated",
headers={"WWW-Authenticate": "Bearer"},
)
else:
return None

3
tests/test_security_openid_connect.py

@ -39,7 +39,8 @@ def test_security_oauth2_password_other_header():
def test_security_oauth2_password_bearer_no_header():
response = client.get("/users/me")
assert response.status_code == 403, response.text
assert response.status_code == 401, response.text
assert response.headers["WWW-Authenticate"] == "Bearer"
assert response.json() == {"detail": "Not authenticated"}

3
tests/test_security_openid_connect_description.py

@ -41,7 +41,8 @@ def test_security_oauth2_password_other_header():
def test_security_oauth2_password_bearer_no_header():
response = client.get("/users/me")
assert response.status_code == 403, response.text
assert response.status_code == 401, response.text
assert response.headers["WWW-Authenticate"] == "Bearer"
assert response.json() == {"detail": "Not authenticated"}

Loading…
Cancel
Save