webgates is a Rust workspace for authentication, authorization, session-backed login flows, and transport adapters.
This repository is organized as a set of focused crates so you can either start from the main application-facing crate or adopt narrower layers directly.
The repository is organized into focused crates with clear boundaries:
webgates— main application-facing composition crate for gates, authentication workflows, optional cookies, OAuth2, sessions, and observabilitywebgates-core— foundational domain types and authorization primitives with no HTTP, codec, or session dependencieswebgates-codecs— JWT codecs, validation helpers, ES384 key handling, and JWKS supportwebgates-secrets— secret value and password-hashing primitives for safe server-side credential handlingwebgates-sessions— framework-agnostic session issuance, renewal, refresh-token rotation, leases, and revocation primitiveswebgates-repositories— repository traits, in-memory implementations, repository-scoped services, and optional SeaORM / SurrealDB backendswebgates-axum— Axum transport adapter for gates, login/logout handlers, JWKS publication, and transparent cookie-backed session renewalwebgates-tonic— tonic server-side transport adapter for bearer-token authentication and authorization in gRPC services
Typical usage patterns:
- start with
webgateswhen you want the main application-facing composition layer - use
webgates-coredirectly for domain-only authorization logic - use
webgates-codecswhen you need JWT handling without the higher-level stack - use
webgates-secretswhen you need hashing and secret handling directly - use
webgates-sessionswhen you need the session lifecycle layer directly - use
webgates-repositorieswhen you need repository contracts or storage backends directly - add
webgates-axumorwebgates-tonicwhen you want transport integration
For most applications, start with the main composition crate:
[dependencies]
webgates = "1.0.0"Common Axum setup with session-backed authentication:
[dependencies]
webgates = { version = "1.0.0", default-features = false, features = ["authn", "codecs", "cookies", "repositories", "secrets", "sessions"] }
webgates-axum = "1.0.0"Use webgates-repositories for persistence backends such as in-memory, SeaORM, or SurrealDB. Backend support is feature-gated in that crate.
Minimum supported Rust version: 1.94.
A typical application stack looks like this:
webgates-coredefines accounts, roles, groups, permissions, and authorization primitiveswebgatescomposes the core model with higher-level auth flows and optional featureswebgates-codecs,webgates-secrets,webgates-sessions, andwebgates-repositoriesprovide narrower building blocks behind those higher-level flowswebgates-axumorwebgates-tonicadapts the model to HTTP or gRPC transports
This keeps domain rules, token handling, secret handling, session lifecycle, persistence, and transport concerns in distinct layers.
Feature highlights available across the workspace include:
- cookie and bearer authentication
- explicit authorization policies
- session-backed authentication with refresh-token rotation
- repository contracts plus in-memory and database-backed implementations
- JWKS-based distributed verification
- Axum and tonic transport adapters
- optional audit logging and Prometheus integration
When you enable session-backed authentication, the canonical deployment model is:
- an auth authority that verifies credentials, issues auth and refresh tokens, owns session persistence, and performs refresh-token rotation and revocation
- one or more resource services that validate short-lived access tokens locally and enforce authorization policy
- an optional single-node deployment that runs both roles together while preserving the same token and revocation semantics
In that model, refresh-token and session mutation logic stay on the authority, while resource services validate access tokens locally without per-request introspection calls. Revocation consistency across resource nodes is therefore bounded by the short access-token TTL.
For the distributed authority/resource operations guide, including key management and rollout guidance, see docs/distributed-sessions.md.
webgates: https://docs.rs/webgateswebgates-core: https://docs.rs/webgates-corewebgates-codecs: https://docs.rs/webgates-codecswebgates-secrets: https://docs.rs/webgates-secretswebgates-sessions: https://docs.rs/webgates-sessionswebgates-repositories: https://docs.rs/webgates-repositorieswebgates-axum: https://docs.rs/webgates-axumwebgates-tonic: https://docs.rs/webgates-tonic
docs/distributed-sessions.md— distributed deployment operations guideexamples/distributed/README.md— JWKS-first distributed setup exampleexamples/oauth2-github— OAuth2 login flow exampleexamples/prometheus— metrics integration exampleexamples/permission-validationandexamples/permission-registry— permission modeling exampleswebgates-repositories/examples/sea-ormandwebgates-repositories/examples/surrealdb— backend examplesTROUBLESHOOTING.md— common integration and debugging guidance
- keep signing keys persistent and out of source control in production
- avoid logging raw tokens, secrets, or cookies
- align issuer strings, cookie names, and cookie templates across the layers that mint, validate, write, and clear auth state
- enable only the features and crates you actually need
- review the
surrealdbfeature inwebgates-repositoriescarefully before production use
SurrealDB is distributed under the Business Source License 1.1 (BUSL). If you enable the optional SurrealDB backend for development, CI, or distribution, review its license terms and comply with any obligations.
- run the full workspace test suite with
cargo test --workspace --all-features - run workspace checks with
cargo check --workspace --all-features - see crate-specific READMEs for focused API guidance
- see
docs/distributed-sessions.mdfor deployment and rotation procedures - see
CONTRIBUTING.mdfor contributor setup, CI workflow, and local validation commands
MIT