sponsorkit.server
Backend verification: check a supporter's session token without any key.
import sponsorkit.serverBackend verification: check a supporter's session token without any key.
Your frontend or CLI sends its Sponsorkit session token (sks_…) to your backend, which calls verify_session(). The token is sealed by Sponsorkit, so it cannot be forged; the helper also checks that the session is bound to your target set. Nothing is stored.
Example
from sponsorkit.server import verify_session
fc = verify_session(token, {"github": "octocat"})
if fc.active():
unlock_pro_features()Exports#
| Name | Kind | Summary |
|---|---|---|
TargetsArg | type alias | Targets as {"github": ..., "open_collective": ...}, a target param, or a list of target strings. |
averify_session() | function | Async variant of verify_session() (uses AsyncClient). |
verify_session() | function | Verify a session token and return the supporter's live contributions. |
Functions#
verify_session()#
def verify_session(
token: str,
targets: TargetsArg,
*,
api_base_url: str = 'https://api.sponsorkit.io',
request_timeout: float = 30.0,
http_client: httpx.Client | None = None,
timeout: float | None = None,
) -> ContributionResultVerify a session token and return the supporter's live contributions.
Calls GET /api/v1/contributions with the token and checks that the session's target set equals targets (after normalization). Touches no local storage.
request_timeout bounds the HTTP request in seconds (default 30, 0 disables it); it also applies when http_client is given. A timeout raises network_error. timeout is a deprecated alias of request_timeout.
Raises#
SponsorkitError:session_invalid(rejected or malformed token),targets_mismatch(bound to other targets),invalid_config(badtargetsorrequest_timeout) ornetwork_error(API unreachable,5xx,429or an unexpected response;retry_aftercarries the API'sRetry-Afterin seconds when it sent one).
| Parameter | Type | Default | Description |
|---|---|---|---|
token | str | required | The supporter's session token (sks_...), as sent by your client. |
targets | TargetsArg | required | Your targets; the session must be bound to exactly this set (after normalization). |
api_base_url | str | 'https://api.sponsorkit.io' | Sponsorkit API origin (default https://api.sponsorkit.io); self-hosting and tests. |
request_timeout | float | 30.0 | Seconds for the HTTP request (0 disables the timeout); a timeout raises network_error. |
http_client | httpx.Client | None | None | Your own httpx client to send the request with (proxies, custom transports). |
timeout | float | None | None | Deprecated alias of request_timeout. |
Also exported as sponsorkit.verify_session.
averify_session()#
async def averify_session(
token: str,
targets: TargetsArg,
*,
api_base_url: str = 'https://api.sponsorkit.io',
request_timeout: float = 30.0,
http_client: httpx.AsyncClient | None = None,
timeout: float | None = None,
) -> ContributionResultAsync variant of verify_session() (uses httpx.AsyncClient).
| Parameter | Type | Default | Description |
|---|---|---|---|
token | str | required | The supporter's session token (sks_...), as sent by your client. |
targets | TargetsArg | required | Your targets; the session must be bound to exactly this set (after normalization). |
api_base_url | str | 'https://api.sponsorkit.io' | Sponsorkit API origin (default https://api.sponsorkit.io); self-hosting and tests. |
request_timeout | float | 30.0 | Seconds for the HTTP request (0 disables the timeout); a timeout raises network_error. |
http_client | httpx.AsyncClient | None | None | Your own httpx client to send the request with (proxies, custom transports). |
timeout | float | None | None | Deprecated alias of request_timeout. |
Also exported as sponsorkit.averify_session.