vestibule_mist
Mist middleware that wires a `Registry` of `Strategy` values into HTTP endpoints.
vestibule_mist
Mist middleware that wires a Registry of Strategy values into HTTP
endpoints.
Provides request_phase (start an authorization flow, persist state
and code_verifier) and callback_phase (validate state, exchange
code, fetch user, invoke caller’s success handler). Uses the shared
vestibule/state_store for single-use storage of in-flight flow state
and an HMAC-SHA256 signed cookie to bind a browser session to a stored
state entry.
Unlike vestibule_wisp, mist has no built-in signed cookie helper, so
the secret key base must be supplied via new_options/1. There is no
default_options — callers must start from new_options so the type
system enforces a conscious secret choice.
Types
CallbackError
Structured errors that can occur during the OAuth callback phase.
pub type CallbackError(a) { UnknownProvider(provider: String) MissingOrInvalidSessionCookie(reason: SessionCookieError) SessionUnavailable SessionProviderMismatch InvalidCallbackParameters(reason: CallbackParametersError) AuthFailed(error.AuthError(a))}Constructors
UnknownProvider(provider: String)
The requested provider is not registered.
MissingOrInvalidSessionCookie(reason: SessionCookieError)
The signed session cookie set during the request phase is missing or
invalid; reason says which.
SessionUnavailable
The session state was not found, expired, or already used.
SessionProviderMismatch
The signed session belongs to another registered provider.
InvalidCallbackParameters(reason: CallbackParametersError)
Callback parameters could not be extracted from the request; reason
says why.
AuthFailed(error.AuthError(a))
Provider authentication failed.
CallbackParametersError
Why callback parameters could not be extracted from a POST callback body.
pub type CallbackParametersError { QueryNotFormEncoded BodyReadFailed BodyNotUtf8 BodyNotFormEncoded DuplicateParameter(name: String)}Constructors
QueryNotFormEncoded
The callback query string was not valid form/query encoding.
BodyReadFailed
The request body could not be read (e.g. larger than the 64 KiB limit, or a transport failure).
BodyNotUtf8
The request body was not valid UTF-8.
BodyNotFormEncoded
The request body was not valid form/query encoding.
DuplicateParameter(name: String)
A callback parameter name occurred more than once, including once in the query and once in a POST body.
CookieSameSite
How the session cookie’s SameSite attribute is set.
pub type CookieSameSite { Lax CrossSite}Constructors
Lax
SameSite=Lax (default). Sent on top-level GET navigations, which is
how every provider that redirects back with query parameters delivers
its callback.
CrossSite
SameSite=None; Secure. Required for providers that deliver the
callback with a cross-site POST (response_mode=form_post, e.g. Apple):
browsers do not send Lax cookies on cross-site POSTs, so the callback
would fail with MissingOrInvalidSessionCookie(CookieAbsent). Browsers
only honour SameSite=None together with Secure, so Secure is set
even under AllowInsecure.
CookieSecurity
Whether the session cookie is set with the Secure attribute.
pub type CookieSecurity { SecureOnly AllowInsecure}Constructors
SecureOnly
Set Secure so the cookie is only sent over HTTPS, and use a host-bound
(__Host- prefixed) cookie name. Use in production.
AllowInsecure
Omit Secure so the cookie also works over plain HTTP, e.g. local
development without TLS. The cookie name is not host-bound, since
browsers reject __Host- cookies that are not Secure.
Options
Middleware configuration options.
Construct with new_options — the HMAC secret_key_base is mandatory and
has no safe default — then customize with with_cookie_name,
with_session_ttl, with_cookie_security, with_same_site, and
with_recovery_path. The type is opaque so the effective cookie name always
matches the cookie security: host-bound
(__Host- prefixed) under SecureOnly, unprefixed under AllowInsecure
(browsers reject __Host- cookies that are not Secure). A host-bound
name prevents a sibling subdomain from overwriting the session cookie with
a Domain=.example.com cookie of the same name (cookie tossing / session
fixation). Read the effective name with cookie_name.
pub type OptionsOptionsError
Errors returned by new_options.
pub type OptionsError { SecretKeyBaseTooShort( minimum_bytes: Int, actual_bytes: Int )}Constructors
`SecretKeyBaseTooShort(
minimum_bytes: Int, actual_bytes: Int )`
secret_key_base is shorter than minimum_secret_key_base_bytes.
RecoveryPathError
Why a callback recovery path was rejected.
pub type RecoveryPathError { RecoveryPathMustBeLocal}Constructors
RecoveryPathMustBeLocal
The value was not a safe same-origin path.
RouteMount
Configuration for the optional request and callback route helper.
pub type RouteMount(a)RouteMountError
Why an auth route prefix was rejected.
pub type RouteMountError { AuthPathPrefixMustBeAbsolute AuthPathPrefixMustBeCanonical}Constructors
AuthPathPrefixMustBeAbsolute
The prefix must be an absolute path such as /auth.
AuthPathPrefixMustBeCanonical
The prefix must contain only canonical, non-empty path segments.
SessionCookieError
Why the signed session cookie could not be used.
The distinction matters operationally: CookieAbsent is ordinary user
behaviour (a bookmarked callback URL, a cleared cookie jar, an expired
cookie), while CookieSignatureInvalid means a cookie was presented that
this secret did not sign, which may indicate tampering or a secret
rotation that invalidated in-flight logins.
pub type SessionCookieError { CookieAbsent CookieSignatureInvalid}Constructors
CookieAbsent
No cookie with the configured name was present on the request.
CookieSignatureInvalid
A cookie was present but its HMAC signature did not verify: wrong secret, tampered payload, or a malformed token.
Constants
minimum_secret_key_base_bytes
Minimum length of the HMAC secret_key_base, in bytes. 32 bytes is the
output size of the HMAC-SHA256 used to sign the session cookie; anything
shorter weakens the signature below the hash’s own strength.
pub const minimum_secret_key_base_bytes: IntFunctions
callback_parameters_from_pairs
Convert parsed callback pairs to a dictionary, rejecting duplicate names.
Use this when callback parameters are extracted outside
callback_phase_auth_result; converting to a dictionary first would hide
duplicate OAuth parameters.
pub fn callback_parameters_from_pairs( List(#(String, String)), List(#(String, String))) -> Result(dict.Dict(String, String), CallbackError(a))callback_phase
Phase 2: Handle the OAuth callback and return the Auth result to the
provided callback function.
Supports both GET callbacks (query parameters) and POST callbacks
(form-encoded body), as required by providers like Apple that use
response_mode=form_post. Repeated parameter names are rejected, including
names present in both the query and POST body.
On success, calls on_success with the Auth. On error, returns a
generic HTML error page. Returns 404 if the provider is not registered.
pub fn callback_phase( request.Request(http.Connection), registry: registry.Registry(a), provider: String, store: state_store.StateStore, options: Options, on_success: fn(auth.Auth) -> response.Response(mist.ResponseData)) -> response.Response(mist.ResponseData)callback_phase_auth_result
Phase 2 (structured Result variant): Handle the OAuth callback and return
either the Auth result or a structured CallbackError.
Use this when you want to distinguish provider lookup, session, callback parameter, and provider authentication failures without parsing responses.
Callback parameters are parsed and state is validated before the stored session is consumed, so malformed or wrong-state callbacks do not burn a valid in-flight login.
pub fn callback_phase_auth_result( request.Request(http.Connection), registry: registry.Registry(a), provider: String, store: state_store.StateStore, options: Options) -> Result(auth.Auth, CallbackError(a))callback_phase_auth_result_with_parameters
Phase 2 with pre-extracted callback parameters.
Useful when the caller has already read the request body (or otherwise
resolved the form/query parameters) and wants to hand them in directly.
Generic over the request body type so it can be used in unit tests with
Request(BitArray) or any other body.
pub fn callback_phase_auth_result_with_parameters( request.Request(a), parameters: dict.Dict(String, String), registry: registry.Registry(b), provider: String, store: state_store.StateStore, options: Options) -> Result(auth.Auth, CallbackError(b))callback_phase_result
Phase 2 (Result variant): Handle the OAuth callback and return either the
Auth result or an error Response.
Use this instead of callback_phase when you want to decide how to use the
success value or generated error response yourself.
pub fn callback_phase_result( request.Request(http.Connection), registry: registry.Registry(a), provider: String, store: state_store.StateStore, options: Options) -> Result(auth.Auth, response.Response(mist.ResponseData))callback_recovery
Return stable, non-sensitive recovery metadata for a callback error.
pub fn callback_recovery(CallbackError(a)) -> error.Recoverycookie_name
The effective session cookie name: host-bound (__Host- prefixed) under
SecureOnly cookie security, the unprefixed base name under
AllowInsecure.
pub fn cookie_name(Options) -> Stringcookie_security
The cookie security for these options.
pub fn cookie_security(Options) -> CookieSecuritydirect_client_key
Return a stable admission key from the direct socket peer address.
Use this with request_phase_for_client. The port is intentionally
excluded so reconnecting cannot bypass the per-client limit.
pub fn direct_client_key(request.Request(http.Connection)) -> Result(String, Nil)expire_session_cookie
Expire the in-flight OAuth session cookie on a response.
callback_phase does this automatically after success or a terminal
failure. Call this when using a Result callback variant and constructing
the final response yourself.
pub fn expire_session_cookie( response.Response(a), Options) -> response.Response(a)new_options
Build middleware options with the given HMAC secret_key_base, which must
be at least minimum_secret_key_base_bytes (32) bytes of unpredictable data.
Defaults: host-bound cookie name __Host-vestibule_session, session TTL
600 seconds, SecureOnly cookies, SameSite=Lax. Customize with
with_cookie_name, with_session_ttl, with_cookie_security,
with_same_site, and with_recovery_path.
pub fn new_options(BitArray) -> Result(Options, OptionsError)new_route_mount
Configure request and callback routes below one auth path prefix.
The mount handles GET <prefix>/<provider> and GET or POST
<prefix>/<provider>/callback. Other paths and methods fall through.
pub fn new_route_mount( auth_path_prefix: String, registry: registry.Registry(a), state_store: state_store.StateStore, authorize_options: config.AuthorizeOptions, middleware_options: Options, on_success: fn(auth.Auth) -> response.Response(mist.ResponseData), on_error: fn(CallbackError(a), error.Recovery) -> response.Response(mist.ResponseData)) -> Result(RouteMount(a), RouteMountError)parse_callback_query
Parse a callback query without silently replacing malformed input.
pub fn parse_callback_query(option.Option(String)) -> Result(List(#(String, String)), CallbackError(a))recovery_path
Return the configured same-origin recovery path.
pub fn recovery_path(Options) -> option.Option(String)request_phase
Phase 1: Redirect the user to the OAuth provider.
Looks up the provider in the registry, generates an authorization URL with
PKCE parameters, stores the CSRF state and code verifier in store, sets
a signed session cookie, and returns a 302 response.
Returns 404 if the provider is not registered, or a generic 400 HTML error if URL generation or state persistence fails.
The direct socket peer address is the admission key. Forwarded headers are not trusted.
pub fn request_phase( request.Request(http.Connection), registry: registry.Registry(a), provider: String, store: state_store.StateStore, authorize_options: config.AuthorizeOptions, options: Options) -> response.Response(mist.ResponseData)request_phase_for_client
Start authorization with a stable identifier for the direct client.
Use the socket peer address, or an identifier supplied by a trusted edge that also rate-limits requests. Do not use forwarded headers without validating the proxy chain.
pub fn request_phase_for_client( request.Request(a), registry: registry.Registry(b), provider: String, store: state_store.StateStore, authorize_options: config.AuthorizeOptions, options: Options, client_key: String) -> response.Response(mist.ResponseData)request_phase_for_direct_client
Start authorization using the direct socket peer as the admission key.
If Mist cannot read the peer address, this fails closed with 429 and does not create state.
pub fn request_phase_for_direct_client( request.Request(http.Connection), registry: registry.Registry(a), provider: String, store: state_store.StateStore, authorize_options: config.AuthorizeOptions, options: Options) -> response.Response(mist.ResponseData)request_phase_with_shared_bucket
Start authorization using one shared admission bucket.
This lets any eight concurrent anonymous starts deny new starts, so prefer
request_phase or request_phase_for_client. Use this only behind an
upstream rate limit.
pub fn request_phase_with_shared_bucket( request.Request(a), registry: registry.Registry(b), provider: String, store: state_store.StateStore, authorize_options: config.AuthorizeOptions, options: Options) -> response.Response(mist.ResponseData)route
Handle a mounted auth route using Mist’s direct socket peer.
None means that the host router must continue routing the request.
pub fn route( request.Request(http.Connection), mount: RouteMount(a)) -> option.Option(response.Response(mist.ResponseData))route_for_client
Handle a mounted auth route using a trusted client admission key.
Use this behind a trusted edge that supplies and rate-limits the identity.
pub fn route_for_client( request.Request(http.Connection), mount: RouteMount(a), client_key: String) -> option.Option(response.Response(mist.ResponseData))same_site
The session cookie’s SameSite setting for these options.
pub fn same_site(Options) -> CookieSameSitesession_ttl
The validated session TTL for these options.
pub fn session_ttl(Options) -> session_ttl.SessionTtlwith_cookie_name
Set a custom session cookie name.
The name is stored without any __Host- prefix (one is stripped when
present); the prefix is applied automatically under SecureOnly cookie
security. See the Options docs.
pub fn with_cookie_name( Options, String) -> Optionswith_cookie_security
Set whether the session cookie requires HTTPS. See CookieSecurity.
pub fn with_cookie_security( Options, CookieSecurity) -> Optionswith_recovery_path
Set a same-origin path for the default callback error page.
Absolute URLs, network-path references, backslashes, control characters,
and HTML delimiters return Error(RecoveryPathMustBeLocal).
pub fn with_recovery_path( Options, String) -> Result(Options, RecoveryPathError)with_same_site
Set the session cookie’s SameSite attribute. See CookieSameSite.
pub fn with_same_site( Options, CookieSameSite) -> Optionswith_session_ttl
Set how long an in-flight authorization flow (and its session cookie) stays valid.
pub fn with_session_ttl( Options, session_ttl.SessionTtl) -> Options