Skip to main content

Crate grow_oidc

Crate grow_oidc 

Source
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§

blockingblocking
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.
testingtesting
Test support (feature testing): in-memory fakes and the conformance runner (SPEC §6).

Structs§

AuthUser
The authenticated user of a verified access token.
OidcClient
Async client for OIDC. Cheap to clone (clones share one connection pool).
OidcConfig
Immutable client configuration; build it with OidcConfig::builder or OidcConfig::from_env. Debug output redacts every credential.
OidcConfigBuilder
Builder for OidcConfig. Values set here win over the environment.
OidcLayertower
Layer that verifies the bearer token of every request and inserts the AuthUser into the request extensions (Extension<AuthUser> in axum). Missing or invalid token → 401, IdP unreachable → 503. The response never says why a token was rejected.
OidcServicetower
The service of OidcLayer.
RequireRolesLayertower
Layer placed inside OidcLayer: 401 without an AuthUser, 403 unless the user has at least one of the roles (case-insensitive). No roles = any authenticated user.
RequireRolesServicetower
The service of RequireRolesLayer.
Verifier
Verifies OIDC access tokens (JWT) against the issuer’s JWKS. Cheap to clone; thread-safe.
VerifierOptions
Options of a Verifier. Default gives the documented defaults (issuer/audience empty).

Constants§

DEFAULT_ALGORITHMS
Accepted algorithms by default: every supported one (asymmetric only; none and HMAC are never accepted). ES512 is not supported (ring has no P-521).
DEFAULT_CLOCK_SKEW
Default tolerance applied to exp and nbf.
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-kid refetches.
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 Authorization header 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’s name (Casdoor), code, role or value. Duplicates are removed, order is kept.
has_any_role
True when have contains at least one of required (case-insensitive); an empty required means any authenticated user.
relative_endpoint
Path of endpoint relative to the provider URL base: the part after base when the endpoint starts with it (keeps realm prefixes out), else the endpoint’s own path and query.

Type Aliases§

ClockFn
A clock returning the current time (tests inject a fake one).
OidcError
Service-prefixed alias of Error.