Skip to main content

Crate oauthkit

Crate oauthkit 

Source
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 by rules/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, and flow::api_key share 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 CredentialStore the 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§

discovery
OpenID Connect discovery.
flow
The three sign-in flows and the token machinery they share.

Structs§

ApiKeyConfig
Configuration for API-key sign-in.
AuthClient
A high-level facade binding a Registry to a CredentialStore, plus the flow entry points. A CLI can use this directly or drop down to flow and Registry for finer control.
DeviceCodeConfig
Configuration for a device-code (RFC 8628) flow.
MemoryStore
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.
OAuthConfig
Configuration for an authorization-code + PKCE OAuth flow.
PkceCodes
A PKCE verifier/challenge pair for one authorization request.
Provider
A single sign-in-able provider.
Registry
The set of known providers.

Enums§

AuthMethod
One authentication method a provider offers.
Credential
The material a completed sign-in yields for one provider.
CredentialKind
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§

CredentialStore
A pluggable persistence backend for credentials.

Functions§

generate_pkce
Generate a fresh S256 PKCE pair.
generate_state
Generate an opaque, URL-safe anti-CSRF state value.

Type Aliases§

Result
Convenience alias used throughout the crate.