Skip to content

Commit 3cd7f84

Browse files
committed
style(formatting): normalize client code formatting and style
- Add a noqa annotation to silence a naming style warning on an HTTP handler method - Reformat method signatures and function calls for consistent style and improved readability - Simplify multi-line raise statements into single-line error constructions - Apply consistent argument formatting across OAuth and discovery client request methods Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
1 parent d30c547 commit 3cd7f84

7 files changed

Lines changed: 49 additions & 43 deletions

File tree

src/authgate/authflow/authcode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class _CallbackHandler(BaseHTTPRequestHandler):
2525
result: dict[str, str] # shared via class attribute set by factory
2626
event: threading.Event
2727

28-
def do_GET(self) -> None:
28+
def do_GET(self) -> None: # noqa: N802
2929
parsed = urlparse(self.path)
3030
if parsed.path != "/callback":
3131
self.send_response(404)

src/authgate/clientcreds/transport.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class BearerAuth(httpx.Auth):
1515
def __init__(self, source: TokenSource) -> None:
1616
self._source = source
1717

18-
def auth_flow(
19-
self, request: httpx.Request
20-
) -> Generator[httpx.Request, httpx.Response, None]:
18+
def auth_flow(self, request: httpx.Request) -> Generator[httpx.Request, httpx.Response, None]:
2119
token = self._source.token()
2220
request.headers["Authorization"] = f"Bearer {token.access_token}"
2321
yield request

src/authgate/credstore/file_store.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ def _read_storage_map(self) -> dict[str, str]:
124124
except FileNotFoundError:
125125
return {}
126126
except (json.JSONDecodeError, OSError) as exc:
127-
raise CredStoreError(
128-
f"failed to read file {self._file_path!r}: {exc}"
129-
) from exc
127+
raise CredStoreError(f"failed to read file {self._file_path!r}: {exc}") from exc
130128

131129
def _write_storage_map(self, data: dict[str, str]) -> None:
132130
content = json.dumps({"data": data}, indent=2)

src/authgate/discovery/async_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ async def _refresh(self) -> Metadata:
4747
url = self._issuer_url + _WELL_KNOWN_PATH
4848
resp = await self._http.get(url)
4949
if resp.status_code != 200:
50-
raise DiscoveryError(
51-
f"discovery: unexpected status {resp.status_code} from {url}"
52-
)
50+
raise DiscoveryError(f"discovery: unexpected status {resp.status_code} from {url}")
5351

5452
body = resp.json()
5553
meta = _parse_metadata(body)

src/authgate/discovery/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def _refresh(self) -> Metadata:
5050
url = self._issuer_url + _WELL_KNOWN_PATH
5151
resp = self._http.get(url)
5252
if resp.status_code != 200:
53-
raise DiscoveryError(
54-
f"discovery: unexpected status {resp.status_code} from {url}"
55-
)
53+
raise DiscoveryError(f"discovery: unexpected status {resp.status_code} from {url}")
5654

5755
body = resp.json()
5856
meta = _parse_metadata(body)

src/authgate/oauth/async_client.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ async def request_device_code(self, scopes: list[str] | None = None) -> DeviceAu
8989

9090
async def exchange_device_code(self, device_code: str) -> Token:
9191
"""Exchange a device code for tokens (RFC 8628 SS3.4)."""
92-
return await self._token_request({
93-
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
94-
"device_code": device_code,
95-
"client_id": self._client_id,
96-
})
92+
return await self._token_request(
93+
{
94+
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
95+
"device_code": device_code,
96+
"client_id": self._client_id,
97+
}
98+
)
9799

98100
async def exchange_auth_code(
99101
self,
@@ -127,11 +129,13 @@ async def client_credentials(self, scopes: list[str] | None = None) -> Token:
127129

128130
async def refresh_token(self, refresh_token: str) -> Token:
129131
"""Exchange a refresh token for new tokens (RFC 6749 SS6)."""
130-
return await self._token_request({
131-
"grant_type": "refresh_token",
132-
"refresh_token": refresh_token,
133-
"client_id": self._client_id,
134-
})
132+
return await self._token_request(
133+
{
134+
"grant_type": "refresh_token",
135+
"refresh_token": refresh_token,
136+
"client_id": self._client_id,
137+
}
138+
)
135139

136140
async def revoke(self, token: str) -> None:
137141
"""Revoke a token (RFC 7009)."""
@@ -148,11 +152,14 @@ async def introspect(self, token: str) -> IntrospectionResult:
148152
"""Introspect a token (RFC 7662)."""
149153
if not self._endpoints.introspection_url:
150154
raise OAuthError("invalid_request", "introspection endpoint not configured")
151-
resp = await self._post_form(self._endpoints.introspection_url, {
152-
"token": token,
153-
"client_id": self._client_id,
154-
"client_secret": self._client_secret,
155-
})
155+
resp = await self._post_form(
156+
self._endpoints.introspection_url,
157+
{
158+
"token": token,
159+
"client_id": self._client_id,
160+
"client_secret": self._client_secret,
161+
},
162+
)
156163
body = resp.json()
157164
return IntrospectionResult(
158165
active=body.get("active", False),

src/authgate/oauth/client.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ def request_device_code(self, scopes: list[str] | None = None) -> DeviceAuth:
8989

9090
def exchange_device_code(self, device_code: str) -> Token:
9191
"""Exchange a device code for tokens (RFC 8628 SS3.4)."""
92-
return self._token_request({
93-
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
94-
"device_code": device_code,
95-
"client_id": self._client_id,
96-
})
92+
return self._token_request(
93+
{
94+
"grant_type": "urn:ietf:params:oauth:grant-type:device_code",
95+
"device_code": device_code,
96+
"client_id": self._client_id,
97+
}
98+
)
9799

98100
def exchange_auth_code(
99101
self,
@@ -127,11 +129,13 @@ def client_credentials(self, scopes: list[str] | None = None) -> Token:
127129

128130
def refresh_token(self, refresh_token: str) -> Token:
129131
"""Exchange a refresh token for new tokens (RFC 6749 SS6)."""
130-
return self._token_request({
131-
"grant_type": "refresh_token",
132-
"refresh_token": refresh_token,
133-
"client_id": self._client_id,
134-
})
132+
return self._token_request(
133+
{
134+
"grant_type": "refresh_token",
135+
"refresh_token": refresh_token,
136+
"client_id": self._client_id,
137+
}
138+
)
135139

136140
def revoke(self, token: str) -> None:
137141
"""Revoke a token (RFC 7009)."""
@@ -148,11 +152,14 @@ def introspect(self, token: str) -> IntrospectionResult:
148152
"""Introspect a token (RFC 7662)."""
149153
if not self._endpoints.introspection_url:
150154
raise OAuthError("invalid_request", "introspection endpoint not configured")
151-
resp = self._post_form(self._endpoints.introspection_url, {
152-
"token": token,
153-
"client_id": self._client_id,
154-
"client_secret": self._client_secret,
155-
})
155+
resp = self._post_form(
156+
self._endpoints.introspection_url,
157+
{
158+
"token": token,
159+
"client_id": self._client_id,
160+
"client_secret": self._client_secret,
161+
},
162+
)
156163
body = resp.json()
157164
return IntrospectionResult(
158165
active=body.get("active", False),

0 commit comments

Comments
 (0)