Expand description
§oauthkit
A provider-registry-driven OAuth SDK for command-line tools. It gives any CLI the breadth of provider sign-in that model tools need (authorization-code with PKCE, device-code, and API-key), without hard-coding a single provider.
§Design
- One data-driven registry. Providers are declared as data
(
Registry, backed byrules/providers.toml). A CLI extends the set by merging its own TOML, never by editing this crate. - Three flows, one token path.
flow::authorization_code,flow::device_code, andflow::api_keyshare one token-exchange and error-parsing path, so success/failure semantics live in one place. - UI-agnostic. The SDK returns URLs, user codes, and
Credentials. The CLI owns all rendering (its own look and feel). - Pluggable storage. Persistence is a
CredentialStorethe CLI supplies. - No silent fallback. Every flow fails loud: a state mismatch, an OAuth
error, or a timeout returns an
Error, never a degraded success.
§Minimal usage
use oauthkit::{AuthClient, CredentialStore, MemoryStore};
let client = AuthClient::builtin(MemoryStore::new())?;
for provider in client.providers() {
println!("{} ({})", provider.display_name, provider.id);
}
// API-key sign-in for a provider that offers it.
let credential = client.accept_api_key("anthropic", "sk-ant-...")?;
client.store().put(&credential)?;Re-exports§
pub use discovery::OidcMetadata;pub use discovery::discover;pub use flow::authorization_code::constant_time_eq;
Modules§
Structs§
- ApiKey
Config - Configuration for API-key sign-in.
- Auth
Client - A high-level facade binding a
Registryto aCredentialStore, plus the flow entry points. A CLI can use this directly or drop down toflowandRegistryfor finer control. - Device
Code Config - Configuration for a device-code (RFC 8628) flow.
- Memory
Store - A process-lifetime, thread-safe in-memory store. Handy for tests and for CLIs that manage their own persistence and only need the SDK’s flow orchestration.
- OAuth
Config - Configuration for an authorization-code + PKCE OAuth flow.
- Pkce
Codes - A PKCE verifier/challenge pair for one authorization request.
- Provider
- A single sign-in-able provider.
- Registry
- The set of known providers.
Enums§
- Auth
Method - One authentication method a provider offers.
- Credential
- The material a completed sign-in yields for one provider.
- Credential
Kind - Which flow minted a
Credential. - Error
- Everything that can go wrong during provider discovery or a sign-in flow.
Constants§
- DEFAULT_
SIGN_ IN_ TIMEOUT - The SDK’s default sign-in timeout for interactive flows.
Traits§
- Credential
Store - A pluggable persistence backend for credentials.
Functions§
- generate_
pkce - Generate a fresh S256 PKCE pair.
- generate_
state - Generate an opaque, URL-safe anti-CSRF
statevalue.
Type Aliases§
- Result
- Convenience alias used throughout the crate.