mirror of
https://github.com/AstrBotDevs/AstrBot.git
synced 2026-10-16 15:06:04 +08:00
fix(provider): apply OAuth formatting and guard client cleanup
Apply the exact Ruff 0.15.22 CI formatting diff and defensively guard optional HTTP client cleanup. Restore the unmodified CI workflow after diagnostics; keep the pull request focused on provider OAuth support.
This commit is contained in:
@@ -27,9 +27,8 @@ jobs:
|
||||
|
||||
- name: Check code formatting with ruff
|
||||
run: |
|
||||
uvx --from ruff==0.15.22 ruff format --diff .
|
||||
uvx --from ruff==0.15.22 ruff format --check .
|
||||
|
||||
- name: Check code style with ruff
|
||||
if: success() || failure()
|
||||
run: |
|
||||
uvx --from ruff==0.15.22 ruff check .
|
||||
|
||||
@@ -176,7 +176,9 @@ class OAuth2Session:
|
||||
state = secrets.token_urlsafe(32)
|
||||
verifier = secrets.token_urlsafe(64)
|
||||
challenge = (
|
||||
base64.urlsafe_b64encode(hashlib.sha256(verifier.encode("ascii")).digest())
|
||||
base64.urlsafe_b64encode(
|
||||
hashlib.sha256(verifier.encode("ascii")).digest()
|
||||
)
|
||||
.rstrip(b"=")
|
||||
.decode("ascii")
|
||||
)
|
||||
|
||||
@@ -45,9 +45,10 @@ class OAuthProviderPlugin(Star):
|
||||
}
|
||||
settings["scopes"] = tuple(self.config.get("scopes", []))
|
||||
# Changing the supplier/client must never reuse another account's token.
|
||||
self.storage_key = "oauth:" + hashlib.sha256(
|
||||
json.dumps(settings, sort_keys=True).encode()
|
||||
).hexdigest()
|
||||
self.storage_key = (
|
||||
"oauth:"
|
||||
+ hashlib.sha256(json.dumps(settings, sort_keys=True).encode()).hexdigest()
|
||||
)
|
||||
self.http = httpx.AsyncClient(proxy=self.config.get("proxy") or None)
|
||||
try:
|
||||
self.oauth = OAuth2Session(
|
||||
@@ -98,7 +99,8 @@ class OAuthProviderPlugin(Star):
|
||||
await self.oauth.close()
|
||||
if self.provider_class is not None:
|
||||
unregister_provider_adapter(PROVIDER_TYPE, self.provider_class)
|
||||
await self.http.aclose()
|
||||
if self.http is not None:
|
||||
await self.http.aclose()
|
||||
raise
|
||||
|
||||
async def load_token(self) -> OAuth2Token | None:
|
||||
|
||||
Reference in New Issue
Block a user