webgates
User-focused composition crate for building a practical webgates application stack.
webgates builds on webgates-core and adds optional higher-level capabilities such as authentication workflows, framework-agnostic gate builders, cookie configuration, JWT support, sessions, secrets, OAuth2, and observability.
Most application developers should start here rather than wiring lower-level crates together manually.
Who this crate is for
Use webgates when you want to:
- depend on one crate as the main application-facing entry point
- configure framework-agnostic cookie, bearer, or OAuth2 gates
- use higher-level login/logout orchestration
- add optional JWT, cookie, repository, secret, and session support through features
- keep transport-specific concerns in adapter crates while application auth logic stays here
If you only need the domain model and authorization primitives, use webgates-core directly.
What you work with in this crate
Most developers can approach webgates through four ideas:
gategives you framework-agnostic gate builders and policy compositionauthngives you higher-level authentication workflows- feature flags add lower-level capabilities such as codecs, cookies, secrets, repositories, sessions, audit logging, and Prometheus integration
- adapter crates translate this crate into framework-specific HTTP or gRPC behavior
Install
Standard dependency declaration:
[]
= "1.0.0"
This crate enables no optional features by default. Use default-features = false
when you want to make that choice explicit in your manifest or pair it with an
explicit feature list.
Minimal setup with no optional features:
[]
= { = "1.0.0", = false }
Custom setup with only selected capabilities:
[]
= { = "1.0.0", = false, = ["codecs", "cookies", "authn"] }
Quick start
use Arc;
use Account;
use AccessPolicy;
use ;
use Gate;
use Group;
use Role;
type AppClaims = ;
let codec = new;
let gate =
.require_login
.with_policy;
Core concepts
1. Gates are the main runtime-facing concept
Framework-agnostic access gates include:
Gate::cookie("issuer", codec)for JWTs in HTTP-only cookiesGate::bearer("issuer", codec)forAuthorization: Bearerwith_static_token(...)for static bearer-token modeallow_anonymous_with_optional_user()for non-blocking optional user contextrequire_login()for baseline role plus supervisors
2. Policies stay explicit and composable
Authorization policies are explicit and composable:
AccessPolicy::require_role(..)AccessPolicy::require_role_or_supervisor(..)AccessPolicy::require_group(..)AccessPolicy::require_permission("domain:action")
3. Features control how much stack you bring in
The webgates crate ships with no enabled default features. Enable only the features you need.
default = [](no default features)full: enables the standard composed stackauthn: authentication servicescodecs: JWT codec support viawebgates-codecscookies: cookie templates and cookie-backed helpersoauth2: OAuth2 supportrepositories: repository contracts used by higher-level workflowssecrets: hashing and secret handling viawebgates-secretssessions: framework-agnostic session lifecycle and renewal primitives viawebgates-sessionsaudit-logging: structured audit events withtracingprometheus: Prometheus metrics support; impliesaudit-loggingwasm: WASM-oriented build support
Session-backed authentication
Enable the sessions feature when you want short-lived auth JWTs backed by long-lived refresh-token session state.
This adds access to the framework-agnostic session layer through webgates::sessions, including:
- typed session and session-family models
- session issuance, renewal, and revocation services
- opaque refresh-token generation and hashing primitives
- repository contracts for session persistence, rotation, leases, and revocation
- an in-memory repository for tests and local development
Typical composition for session-backed login and renewal:
[]
= { = "1.0.0", = false, = ["authn", "codecs", "cookies", "repositories", "secrets", "sessions"] }
For HTTP adapters, keep cookie extraction and response mutation in the adapter crate. In the Axum integration, use:
webgates_axum::route_handlers::login_with_sessionswebgates_axum::route_handlers::logout_with_sessionswebgates_axum::session::CookieSessionLayer
Recommended onboarding path
If you are new to this crate, I recommend this order:
gateauthz::access_policyauthnif you need login/logout workflows- feature-specific areas such as
codecs,cookies,sessions, oroauth2 - the adapter crate that matches your transport layer
Security checklist
- use a persistent JWT key in production
- keep issuer strings identical between login and gates
- align cookie names and templates between writers and readers
- set
Secure,HttpOnly, andSameSiteappropriately - rate-limit login and validate inputs at boundaries
- avoid logging secrets or tokens
- use correlation IDs for observability
- enable
audit-loggingandprometheuswhere appropriate
License
MIT
Additional backend note:
- SurrealDB support is provided by
webgates-repositoriesthrough itssurrealdbfeature. Review and comply with SurrealDB's BUSL-1.1 terms before enabling it in production.