oauth-toolkit
Shared OAuth2/OIDC primitives — crypto, PKCE, scopes, CSRF, social login, OIDC, JWKS validation.
Modules
| Module | Purpose |
|---|---|
crypto |
SHA-256 hex, HMAC-SHA256, opaque token generation |
pkce |
RFC 7636 S256 verification |
scope |
Parse/validate OAuth scopes |
redirect |
URI exact-match validation |
csrf |
CsrfStore trait (memory + Redis backends) |
social |
GitHub + Google OAuth2 flows |
providers |
Canonical endpoint constants + mail presets (Gmail, Outlook, Yahoo, AOL, Fastmail) with IMAP/SMTP XOAUTH2 scopes |
loopback |
Desktop loopback redirect capture (RFC 8252): ephemeral 127.0.0.1 bind, PKCE + single-use state, one redirect then shutdown |
token |
Authorization-code exchange (PKCE) and refresh via the token endpoint |
oidc |
Discovery, token exchange, user info, refresh |
oidc_validator |
JWKS-backed token validation |
jwt |
HS256 encode/decode helpers |
Quick Start
use ;
// Hash a token for storage
let hash = sha256_hex;
// Generate PKCE pair
let = generate_pkce_pair;
// Build GitHub authorization URL
let config = SocialProviderConfig ;
let url = build_authorize_url;
// Desktop loopback OAuth2 with a mail provider preset
let provider = gmail;
let flow = start_for_provider?;
println!;
let captured = flow.wait_for_code?; // single-use state, shuts down after one redirect
let tokens = exchange_code.await?;
Contributing
See CONTRIBUTING.md.
License
Licensed under MIT OR Apache-2.0.