Auth¶
Access token introspection.
client.auth # AuthResource
Methods¶
whoami()¶
Verify the current API token and return its metadata.
def whoami(
*,
as_json: bool | None = None,
) -> TokenInfo | dict
HTTP GET /auth/token
Scope any valid token
Returns TokenInfo. Key fields:
Field |
Type |
Description |
|---|---|---|
|
|
|
|
|
UUID of the owning team |
|
|
|
|
|
Explicit scopes (empty for |
|
|
Whether the team is on pro pricing |
Example
info = client.auth.whoami()
print(info.team_id, info.token_type)
for scope in info.scopes:
print("-", scope)
Errors
AuthenticationError(401) — token missing, malformed, expired, or revoked.
Recipes¶
Fail fast on missing scopes¶
REQUIRED = {"orders.create", "campaigns.update"}
info = client.auth.whoami()
missing = REQUIRED - set(info.scopes)
if info.token_type != "full_access" and missing:
raise RuntimeError(f"token missing: {sorted(missing)}")
Log token metadata on startup¶
import logging
info = client.auth.whoami()
logging.info("presscart team=%s type=%s scopes=%s", info.team_id, info.token_type, len(info.scopes))