|
|
@ -667,7 +667,7 @@ class OAuth2ClientCredentials(OAuth2): |
|
|
), |
|
|
), |
|
|
], |
|
|
], |
|
|
scheme_name: Annotated[ |
|
|
scheme_name: Annotated[ |
|
|
Optional[str], |
|
|
str | None, |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
Security scheme name. |
|
|
Security scheme name. |
|
|
@ -677,7 +677,7 @@ class OAuth2ClientCredentials(OAuth2): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
scopes: Annotated[ |
|
|
scopes: Annotated[ |
|
|
Optional[Dict[str, str]], |
|
|
dict[str, str] | None, |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
The OAuth2 scopes that would be required by the *path operations* that |
|
|
The OAuth2 scopes that would be required by the *path operations* that |
|
|
@ -686,7 +686,7 @@ class OAuth2ClientCredentials(OAuth2): |
|
|
), |
|
|
), |
|
|
] = None, |
|
|
] = None, |
|
|
description: Annotated[ |
|
|
description: Annotated[ |
|
|
Optional[str], |
|
|
str | None, |
|
|
Doc( |
|
|
Doc( |
|
|
""" |
|
|
""" |
|
|
Security scheme description. |
|
|
Security scheme description. |
|
|
@ -734,16 +734,12 @@ class OAuth2ClientCredentials(OAuth2): |
|
|
auto_error=auto_error, |
|
|
auto_error=auto_error, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
async def __call__(self, request: Request) -> Optional[str]: |
|
|
async def __call__(self, request: Request) -> str | None: |
|
|
authorization = request.headers.get("Authorization") |
|
|
authorization = request.headers.get("Authorization") |
|
|
scheme, param = get_authorization_scheme_param(authorization) |
|
|
scheme, param = get_authorization_scheme_param(authorization) |
|
|
if not authorization or scheme.lower() != "bearer": |
|
|
if not authorization or scheme.lower() != "bearer": |
|
|
if self.auto_error: |
|
|
if self.auto_error: |
|
|
raise HTTPException( |
|
|
raise self.make_not_authenticated_error() |
|
|
status_code=HTTP_401_UNAUTHORIZED, |
|
|
|
|
|
detail="Not authenticated", |
|
|
|
|
|
headers={"WWW-Authenticate": "Bearer"}, |
|
|
|
|
|
) |
|
|
|
|
|
else: |
|
|
else: |
|
|
return None |
|
|
return None |
|
|
return param |
|
|
return param |
|
|
|