Available on crate feature
sso only.Expand description
OAuth 2.0 / OIDC SSO client support.
Enabled by the sso Cargo feature:
rust-web-server = { version = "17", features = ["sso"] }§Quick start
use std::sync::Arc;
use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::session::SessionStore;
use rust_web_server::sso::{OidcAuth, OidcConfig};
let sessions = Arc::new(SessionStore::new(86_400));
let config = OidcConfig::google(
"my-client-id",
"my-client-secret",
"https://example.com/auth/callback",
);
let app = App::new().wrap(OidcAuth::new(config, sessions));§Module layout
| Sub-module | Purpose |
|---|---|
config | OidcConfig + provider presets + from_env() |
discovery | OidcProvider endpoints + hardcoded presets |
jwks | JwksCache, JWT RS256/ES256 verify, OidcClaims |
pkce | PkceVerifier, PkceChallenge, base64url |
client | OidcClient: auth URL, token exchange, user info |
oidc_auth | OidcAuth middleware |
server | AuthServer — rws as its own OAuth 2.0 Authorization Server (sso-server feature) |
client_store | ClientStore / OAuthClient — clients registered with server::AuthServer (sso-server feature) |
saml | saml::SamlSp — SAML 2.0 Service Provider (sso-saml feature) |
Modules§
- client
- OIDC / OAuth 2.0 client — authorization URL builder, token exchange, and UserInfo fetch.
- client_
store sso-server - Registered OAuth 2.0 clients for
super::server::AuthServer. - config
- OIDC client configuration and provider presets.
- discovery
- OIDC provider discovery and hardcoded presets.
- jwks
- JSON Web Key Set (JWKS) cache and JWT verification.
- oidc_
auth OidcAuthmiddleware — full OIDC / OAuth 2.0 authorization code flow with PKCE, session management, and claim injection.- pkce
- PKCE (Proof Key for Code Exchange) helpers — RFC 7636.
- saml
sso-saml SamlSp— a SAML 2.0 Service Provider middleware.- server
sso-server AuthServer— a minimal OAuth 2.0 Authorization Server / token issuer.
Structs§
- Auth
Server - A minimal OAuth 2.0 Authorization Server — see the module docs.
- Auth
Server Config - Configuration for
AuthServer. - Client
Store - In-memory registry of
OAuthClients, looked up byclient_id. - Jwks
Cache - Thread-safe cache of public keys from a JWKS endpoint.
- OAuth
Client - A registered OAuth 2.0 client.
- Oidc
Auth - OIDC / OAuth 2.0 authentication middleware.
- Oidc
Claims - Standard OIDC claims extracted from an id_token or userinfo response.
- Oidc
Client - A thin OIDC / OAuth 2.0 client that performs the authorization code flow.
- Oidc
Config - All parameters needed to perform an OIDC / OAuth 2.0 authorization flow.
- Oidc
Provider - Endpoint URLs for an OIDC / OAuth 2.0 identity provider.
- Pkce
Challenge - SHA-256 base64url challenge derived from the verifier.
- Pkce
Verifier - Cryptographically random code verifier (43–128 base64url chars, per RFC 7636).
- Signed
In - A signed-in user (
OidcAuth::signed_in). - SsoError
- An error produced by the SSO / OIDC flow.
- Token
Response - Result of a successful token-endpoint exchange.
- Verify
Options - Options for JWT verification.
Enums§
- Grant
Type - An OAuth 2.0 grant type a registered client is authorized to use.