Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/authsome/auth/bundled_providers/notion.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"device_authorization_url": null,
"scopes": [],
"pkce": false,
"client_secret_handling": "basic",
"authorization_method": "basic",
"supports_device_code": false,
"supports_dcr": false
},
Expand Down
2 changes: 1 addition & 1 deletion src/authsome/auth/bundled_providers/x.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"offline.access"
],
"pkce": true,
"client_secret_handling": "basic",
"authorization_method": "basic",
"supports_device_code": false,
"supports_dcr": false
},
Expand Down
12 changes: 7 additions & 5 deletions src/authsome/auth/flows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,23 @@ async def revoke(
if not revocation_url:
return

use_basic = provider.oauth.client_secret_handling == "basic" if provider.oauth else False
use_basic = provider.oauth.authorization_method == "basic" if provider.oauth else False

def _do_revoke(token: str, token_type: str) -> None:
payload: dict[str, str] = {"token": token}
if not use_basic:
auth: tuple[str, str] | None = None
if use_basic:
auth = (client_id or "", client_secret or "")
else:
if client_id:
payload["client_id"] = client_id
if client_secret:
payload["client_secret"] = client_secret
try:
http_client.post(
revocation_url,
data=None if use_basic else payload,
json=payload if use_basic else None,
auth=(client_id or "", client_secret or "") if use_basic else None,
data=payload,
auth=auth,
timeout=15,
)
except Exception as exc:
Expand Down
12 changes: 7 additions & 5 deletions src/authsome/auth/flows/dcr_pkce.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,19 @@ async def _exchange_code( # noqa: PLR0913
"code_verifier": code_verifier,
}

use_basic = provider.oauth.client_secret_handling == "basic"
if not use_basic:
use_basic = provider.oauth.authorization_method == "basic"
auth: tuple[str, str] | None = None
if use_basic:
auth = (client_id, client_secret or "")
else:
body["client_id"] = client_id
if client_secret:
body["client_secret"] = client_secret

resp = http_client.post(
provider.oauth.token_url,
data=None if use_basic else body,
json=body if use_basic else None,
auth=(client_id, client_secret or "") if use_basic else None,
data=body,
auth=auth,
headers={"Accept": "application/json"},
timeout=30,
)
Expand Down
1 change: 0 additions & 1 deletion src/authsome/auth/models/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class OAuthConfig(BaseModel):
device_authorization_url: str | None = None
#: ``json`` = poll token URL with ``POST`` JSON body ``{"device_code": "..."}`` (e.g. Postiz CLI auth).
device_token_request: Literal["oauth2_form", "json"] = "oauth2_form"
client_secret_handling: Literal["post", "basic"] = "post"
scopes: list[str] = Field(default_factory=list)
authorization_params: dict[str, str] = Field(default_factory=dict)
pkce: bool = True
Expand Down
Loading