55from fastapi import Request
66from fastapi .encoders import jsonable_encoder
77from fastapi .openapi .models import HTTPBearer as HTTPBearerModel
8- from fastapi .security import (
9- HTTPAuthorizationCredentials as FastAPIHTTPAuthorizationCredentials ,
10- )
8+ from fastapi .security import HTTPAuthorizationCredentials as FastAPIHTTPAuthorizationCredentials
119from fastapi .security import HTTPBearer
1210from fastapi .security .utils import get_authorization_scheme_param
1311import jwt
@@ -125,9 +123,7 @@ def __init__(
125123
126124 def _check_config (self ) -> None :
127125 if not self .config .audience and self .config .verify_aud :
128- raise ValueError (
129- "Audience must be set in config because verify_aud is True"
130- )
126+ raise ValueError ("Audience must be set in config because verify_aud is True" )
131127 if not self .config .issuer and self .config .verify_iss :
132128 raise ValueError ("Issuer must be set in config because verify_iss is True" )
133129
@@ -152,16 +148,12 @@ def _decode_token(self, token: str) -> dict | None:
152148 raise e
153149 return None
154150
155- async def __call__ (
156- self , request : Request
157- ) -> Optional [HTTPAuthorizationCredentials ]:
151+ async def __call__ (self , request : Request ) -> Optional [HTTPAuthorizationCredentials ]:
158152 authorization = request .headers .get ("Authorization" )
159153 scheme , credentials = get_authorization_scheme_param (authorization )
160154 if not (authorization and scheme and credentials ):
161155 if self .auto_error :
162- raise HTTPException (
163- status_code = HTTP_403_FORBIDDEN , detail = "Not Authenticated"
164- )
156+ raise HTTPException (status_code = HTTP_403_FORBIDDEN , detail = "Not Authenticated" )
165157 return None
166158 if scheme .lower () != "bearer" :
167159 if self .auto_error :
@@ -177,9 +169,7 @@ async def __call__(
177169 status_code = HTTP_403_FORBIDDEN ,
178170 detail = "Invalid Authentication Credentials" ,
179171 )
180- response = HTTPAuthorizationCredentials (
181- scheme = scheme , credentials = credentials , decoded = decoded_token
182- )
172+ response = HTTPAuthorizationCredentials (scheme = scheme , credentials = credentials , decoded = decoded_token )
183173 if self .add_state :
184174 request .state .clerk_auth = response
185175 return response
0 commit comments