sponsorkit.server

Backend verification: check a supporter's session token without any key.

On this page
import sponsorkit.server

Backend 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#

NameKindSummary
TargetsArgtype aliasTargets as {"github": ..., "open_collective": ...}, a target param, or a list of target strings.
averify_session()functionAsync variant of verify_session() (uses AsyncClient).
verify_session()functionVerify 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,
) -> ContributionResult

Verify 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 (bad targets or request_timeout) or network_error (API unreachable, 5xx, 429 or an unexpected response; retry_after carries the API's Retry-After in seconds when it sent one).
ParameterTypeDefaultDescription
tokenstrrequiredThe supporter's session token (sks_...), as sent by your client.
targetsTargetsArgrequiredYour targets; the session must be bound to exactly this set (after normalization).
api_base_urlstr'https://api.sponsorkit.io'Sponsorkit API origin (default https://api.sponsorkit.io); self-hosting and tests.
request_timeoutfloat30.0Seconds for the HTTP request (0 disables the timeout); a timeout raises network_error.
http_clienthttpx.Client | NoneNoneYour own httpx client to send the request with (proxies, custom transports).
timeoutfloat | NoneNoneDeprecated 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,
) -> ContributionResult

Async variant of verify_session() (uses httpx.AsyncClient).

ParameterTypeDefaultDescription
tokenstrrequiredThe supporter's session token (sks_...), as sent by your client.
targetsTargetsArgrequiredYour targets; the session must be bound to exactly this set (after normalization).
api_base_urlstr'https://api.sponsorkit.io'Sponsorkit API origin (default https://api.sponsorkit.io); self-hosting and tests.
request_timeoutfloat30.0Seconds for the HTTP request (0 disables the timeout); a timeout raises network_error.
http_clienthttpx.AsyncClient | NoneNoneYour own httpx client to send the request with (proxies, custom transports).
timeoutfloat | NoneNoneDeprecated alias of request_timeout.

Also exported as sponsorkit.averify_session.