Patreon API Rust Client
An async Rust client library for the Patreon API (v2).
Contents
- Features
- Installation
- Clients
- Environment variables (for examples)
- Quick start
- Webhooks (validate + parse)
- Examples
Features
- OAuth 2.0 authorization flow (authorization URL, code exchange, refresh token)
- User APIs (OAuth user access token)
- Creator/server APIs (creator access token)
- Webhook signature validation (HMAC-SHA256)
- Strongly-typed JSON:API models
- Async API based on
tokio
Installation
Add to your Cargo.toml:
[]
= "0.2"
= { = "1", = ["full"] }
TLS backend features
This crate uses reqwest internally. You can choose the TLS backend via crate features:
native-tls(default): system TLS vianative-tlsrustls:rustls(reqwestrustlsfeature)
Examples:
# Default (native-tls)
= "0.2"
# Force rustls
= { = "0.2", = false, = ["rustls"] }
Clients
| Client | When to use | Token |
|---|---|---|
OAuthClient |
Build authorization URLs, exchange code for token, refresh token |
CLIENT_ID + CLIENT_SECRET |
PatreonUserClient |
Third-party apps acting on behalf of a user | OAuth user access token |
PatreonCreatorClient |
Server-side access for a creator | Creator access token from Patreon developer portal |
Environment variables (for examples)
The examples under examples/ read credentials from environment variables:
CLIENT_IDCLIENT_SECRETREDIRECT_URLUSER_ACCESS_TOKENCREATOR_ACCESS_TOKEN
Some examples also require additional variables (the program will tell you via expect(...)):
OAUTH_CODE,REFRESH_TOKENPORT(used byoauth_localhost_login, default:8080)CAMPAIGN_ID,MEMBER_ID,POST_IDWEBHOOK_URI
Quick start
OAuth (authorization URL, exchange code, refresh token)
use ;
async
User API (identity)
use PatreonUserClient;
async
Creator API (campaigns, members, posts, webhooks)
use PatreonCreatorClient;
async
Webhooks (validate + parse)
Patreon sends webhook requests with:
X-Patreon-Signature: HMAC-SHA256 hex signature of the raw request bodyX-Patreon-Event: event type string (e.g.members:create,posts:publish)
This crate provides WebhookValidator for signature verification and convenient parsing:
use ;
Examples
Run any example with:
cargo run --example <name>
Available examples:
oauth_authorization_urloauth_exchange_codeoauth_localhost_loginoauth_refresh_tokenuser_identityuser_memberships_listuser_memberships_with_campaignsuser_is_patron_of_campaigncreator_campaignscreator_memberscreator_postscreator_webhookscreator_delete_webhook_cliwebhook_validate