Skip to content

Commit 6dac0b1

Browse files
committed
Reformat long lines for readability in oauth2_auth.py
Refactored several long lines and conditional statements to improve code readability and maintain PEP8 compliance. No functional changes were made.
1 parent b4bbdf0 commit 6dac0b1

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

veadk/auth/middleware/oauth2_auth.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,7 @@ async def _fetch_jwks(self) -> dict[str, Any]:
947947
jwks = response.json()
948948
except httpx.HTTPStatusError as e:
949949
logger.error("JWKS fetch failed: %s", e.response.text)
950-
raise HTTPException(
951-
status_code=503, detail="Failed to fetch JWKS"
952-
) from e
950+
raise HTTPException(status_code=503, detail="Failed to fetch JWKS") from e
953951
except httpx.RequestError as e:
954952
logger.error("JWKS request error: %s", e)
955953
raise HTTPException(status_code=503, detail="Failed to fetch JWKS") from e
@@ -975,8 +973,7 @@ async def _get_jwks(self, force_refresh: bool = False) -> dict[str, Any]:
975973
if (
976974
not force_refresh
977975
and self._jwks_cache
978-
and now - self._jwks_cache_time
979-
< self.config.jwks_cache_ttl_seconds
976+
and now - self._jwks_cache_time < self.config.jwks_cache_ttl_seconds
980977
):
981978
return self._jwks_cache
982979

@@ -1028,7 +1025,9 @@ def _prune_introspection_cache(self) -> None:
10281025
]
10291026
for token in expired:
10301027
self._introspection_cache.pop(token, None)
1031-
while len(self._introspection_cache) > self.config.introspection_cache_max_entries:
1028+
while (
1029+
len(self._introspection_cache) > self.config.introspection_cache_max_entries
1030+
):
10321031
self._introspection_cache.pop(next(iter(self._introspection_cache)))
10331032

10341033
def _validate_audience(self, claims: dict[str, Any]) -> None:
@@ -1099,7 +1098,10 @@ async def _validate_with_introspection(self, token: str) -> dict[str, Any]:
10991098
data = {"token": token}
11001099
headers = {"Content-Type": "application/x-www-form-urlencoded"}
11011100
auth = None
1102-
if self.config.introspection_client_id and self.config.introspection_client_secret:
1101+
if (
1102+
self.config.introspection_client_id
1103+
and self.config.introspection_client_secret
1104+
):
11031105
auth = (
11041106
self.config.introspection_client_id,
11051107
self.config.introspection_client_secret,
@@ -1150,9 +1152,7 @@ async def _validate_with_introspection(self, token: str) -> dict[str, Any]:
11501152
if self.config.issuer:
11511153
issuer = result.get("iss")
11521154
if issuer and issuer != self.config.issuer:
1153-
raise HTTPException(
1154-
status_code=403, detail="Token issuer not allowed"
1155-
)
1155+
raise HTTPException(status_code=403, detail="Token issuer not allowed")
11561156

11571157
self._validate_audience(result)
11581158

@@ -1736,7 +1736,9 @@ async def oauth2_middleware(request: Request, call_next):
17361736

17371737
if session and not session.is_expired():
17381738
try:
1739-
claims = await oauth2_handler.validate_access_token(session.access_token)
1739+
claims = await oauth2_handler.validate_access_token(
1740+
session.access_token
1741+
)
17401742
except HTTPException as exc:
17411743
if exc.status_code >= 500:
17421744
return JSONResponse(

0 commit comments

Comments
 (0)