Expand description
§grow-oidc
Rust SDK for OIDC by Grow Codes.
use grow_oidc::{OidcClient, OidcConfig};
let client = OidcClient::new(OidcConfig::from_env()?)?;
let health = client.health().await?;
println!("healthy: {}", health.healthy);
client.close().await;Features: blocking (a blocking client), testing (in-memory fakes and the conformance
runner)
.
Re-exports§
pub use crate::core::Error;pub use crate::core::ErrorCode;pub use crate::core::HealthStatus;pub use crate::core::Result;pub use crate::core::RetryPolicy;pub use crate::core::Secret;
Modules§
- blocking
blocking - Blocking wrapper (feature
blocking). Each client owns a tokio runtime with one worker thread, so background work (log batching, exports, watchers, retries’ timers) keeps running between blocking calls. - core
- Shared core: errors, configuration, secrets in config, redaction, retries and transport.
- testing
testing - Test support (feature
testing): in-memory fakes and the conformance runner (SPEC §6).
Structs§
- Auth
User - The authenticated user of a verified access token.
- Oidc
Client - Async client for OIDC. Cheap to clone (clones share one connection pool).
- Oidc
Config - Immutable client configuration; build it with
OidcConfig::builderorOidcConfig::from_env.Debugoutput redacts every credential. - Oidc
Config Builder - Builder for
OidcConfig. Values set here win over the environment. - Oidc
Layer tower - Layer that verifies the bearer token of every request and inserts the
AuthUserinto the request extensions (Extension<AuthUser>in axum). Missing or invalid token → 401, IdP unreachable → 503. The response never says why a token was rejected. - Oidc
Service tower - The service of
OidcLayer. - Require
Roles Layer tower - Layer placed inside
OidcLayer: 401 without anAuthUser, 403 unless the user has at least one of the roles (case-insensitive). No roles = any authenticated user. - Require
Roles Service tower - The service of
RequireRolesLayer. - Verifier
- Verifies OIDC access tokens (JWT) against the issuer’s JWKS. Cheap to clone; thread-safe.
- Verifier
Options - Options of a
Verifier.Defaultgives the documented defaults (issuer/audience empty).
Constants§
- DEFAULT_
ALGORITHMS - Accepted algorithms by default: every supported one (asymmetric only;
noneand HMAC are never accepted). ES512 is not supported (ringhas no P-521). - DEFAULT_
CLOCK_ SKEW - Default tolerance applied to
expandnbf. - DEFAULT_
HTTP_ TIMEOUT - Default timeout of discovery and JWKS requests.
- DEFAULT_
JWKS_ CACHE_ TTL - Default JWKS cache lifetime.
- DEFAULT_
JWKS_ REFRESH_ COOLDOWN - Default minimum interval between two unknown-
kidrefetches. - DEFAULT_
URL - Endpoint used when neither the builder nor the environment sets one.
- DISCOVERY_
PATH - Discovery document path, relative to the provider URL (realm prefixes such as Keycloak’s kept).
Functions§
- bearer_
token - Returns the bearer token of an
Authorizationheader value (scheme case-insensitive). - claim_
at - Value at a claim name (
roles) or dotted path (realm_access.roles); an exact top-level match wins. - extract_
roles - Role names of the claim at
roles_claim: a string is split on commas and whitespace; an array yields each string, or each object’sname(Casdoor),code,roleorvalue. Duplicates are removed, order is kept. - has_
any_ role - True when
havecontains at least one ofrequired(case-insensitive); an emptyrequiredmeans any authenticated user. - relative_
endpoint - Path of
endpointrelative to the provider URLbase: the part afterbasewhen the endpoint starts with it (keeps realm prefixes out), else the endpoint’s own path and query.