Docs menu: vestibule_wisp

vestibule_wisp

Wisp middleware that wires a `Registry` of `Strategy` values into HTTP endpoints.

vestibule_wisp

Wisp 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 a StateStore for single-use storage of in-flight flow state.

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.

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), set via wisp.set_cookie. 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 always set for this mode, even for plain-HTTP localhost requests.

CookieSecurity

Whether the session cookie requires HTTPS.

pub type CookieSecurity {
SecureOnly
AllowInsecure
}

Constructors

SecureOnly

Use a host-bound (__Host- prefixed) cookie name. Use in production.

wisp.set_cookie sets Secure, Path=/, and no Domain for any request that is not plain HTTP on localhost, which is exactly what browsers require before they will accept a __Host- cookie.

AllowInsecure

Use an unprefixed cookie name so the session also works over plain HTTP, e.g. local development without TLS.

wisp.set_cookie omits Secure for plain-HTTP localhost requests, and browsers reject a __Host- cookie that is not Secure — so under SecureOnly the cookie would be silently dropped and every callback would fail with MissingOrInvalidSessionCookie(CookieAbsent).

Options

Middleware configuration options.

Construct with default_options and 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, which would let an attacker plant their own in-flight flow state and fixate the victim’s session — especially dangerous in account-linking flows. Read the effective name with cookie_name.

pub type Options

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 application’s secret key base 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 Wisp could not verify its signature: tampered payload, a malformed token, or a different secret key base.

Functions

callback_parameters_from_pairs

Convert parsed callback pairs to a dictionary, rejecting duplicate names.

This is also useful for adapters that extract a Wisp request before calling Vestibule. Pass query and body pairs separately; a name present in both is a duplicate.

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 result. On error, returns an HTML error page. Returns 404 if the provider is not registered.

pub fn callback_phase(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
on_success: fn(auth.Auth) -> response.Response(wisp.Body)
) -> response.Response(wisp.Body)

callback_phase_auth_result

Phase 2 (structured Result variant): Handle the OAuth callback and return either the Auth result or a structured callback error.

Use this when you want to distinguish provider lookup, session, callback parameter, and provider authentication failures without parsing responses.

pub fn callback_phase_auth_result(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore
) -> Result(auth.Auth, CallbackError(a))

callback_phase_auth_result_with_options

Phase 2 (structured Result variant): Handle the OAuth callback using custom middleware options.

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_with_options(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
options: Options
) -> Result(auth.Auth, CallbackError(a))

callback_phase_result

Phase 2 (Result variant): Handle the OAuth callback and return either the Auth result or an error Response.

Supports both GET callbacks (query parameters) and POST callbacks (form-encoded body). See callback_phase for details.

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(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore
) -> Result(auth.Auth, response.Response(wisp.Body))

callback_phase_result_with_options

Phase 2 (Result variant): Handle the OAuth callback using custom middleware options.

pub fn callback_phase_result_with_options(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
options: Options
) -> Result(auth.Auth, response.Response(wisp.Body))

callback_phase_with_options

Phase 2: Handle the OAuth callback using custom middleware options.

pub fn callback_phase_with_options(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
on_success: fn(auth.Auth) -> response.Response(wisp.Body),
options: Options
) -> response.Response(wisp.Body)

callback_recovery

Return stable, non-sensitive recovery metadata for a callback error.

pub fn callback_recovery(CallbackError(a)) -> error.Recovery

The effective session cookie name: host-bound (__Host- prefixed) under SecureOnly cookie security, the unprefixed base name under AllowInsecure.

pub fn cookie_name(Options) -> String

The cookie security for these options.

pub fn cookie_security(Options) -> CookieSecurity

default_options

Default middleware options.

Uses the host-bound __Host-vestibule_session signed cookie with a 600-second session TTL and SecureOnly cookie security. The __Host- prefix makes browsers reject the cookie unless it is set with Secure, Path=/, and no Domain attribute, which prevents a sibling subdomain from tossing/fixating the OAuth session (see the Options docs).

wisp.set_cookie sets Path=/ and no Domain always, and Secure for every request except plain HTTP on localhost — so these defaults meet the __Host- requirements in production but not when developing over http://localhost. For that case use with_cookie_security(AllowInsecure).

pub fn default_options() -> Options

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(wisp.Body),
request.Request(internal.Connection),
Options
) -> response.Response(wisp.Body)

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(wisp.Body),
on_error: fn(CallbackError(a), error.Recovery) -> response.Response(wisp.Body)
) -> 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 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 the state store, sets a signed session cookie, and returns a redirect response.

Returns 404 if the provider is not registered.

Wisp does not expose the direct socket peer. This compatibility entry point therefore fails closed with 429. Use request_phase_for_client, or make a deliberate shared-bucket choice with request_phase_with_shared_bucket.

pub fn request_phase(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
authorize_options: config.AuthorizeOptions
) -> response.Response(wisp.Body)

request_phase_for_client

Start authorization with default options and a stable identifier for the direct client. See request_phase_for_client_with_options.

pub fn request_phase_for_client(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
authorize_options: config.AuthorizeOptions,
client_key: String
) -> response.Response(wisp.Body)

request_phase_for_client_with_options

Start authorization with a stable identifier for the direct client.

Obtain this value from the server connection or a trusted edge that enforces its own rate limit. Do not pass Forwarded or X-Forwarded-For directly: clients can forge those headers unless the application first validates and removes untrusted hops.

pub fn request_phase_for_client_with_options(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
authorize_options: config.AuthorizeOptions,
middleware_options: Options,
client_key: String
) -> response.Response(wisp.Body)

request_phase_with_options

Phase 1: Redirect user to the OAuth provider using custom middleware options. Fails closed until the caller supplies an admission identity.

pub fn request_phase_with_options(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
authorize_options: config.AuthorizeOptions,
middleware_options: Options
) -> response.Response(wisp.Body)

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_for_client. Use this only behind an upstream rate limit.

pub fn request_phase_with_shared_bucket(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
authorize_options: config.AuthorizeOptions
) -> response.Response(wisp.Body)

request_phase_with_shared_bucket_and_options

Start authorization using custom options and one shared admission bucket.

pub fn request_phase_with_shared_bucket_and_options(
request.Request(internal.Connection),
registry: registry.Registry(a),
provider: String,
state_store: state_store.StateStore,
authorize_options: config.AuthorizeOptions,
middleware_options: Options
) -> response.Response(wisp.Body)

route_for_client

Handle a mounted auth route using a trusted direct-client admission key.

None means that the host router must continue routing the request.

pub fn route_for_client(
request.Request(internal.Connection),
mount: RouteMount(a),
client_key: String
) -> option.Option(response.Response(wisp.Body))

same_site

The session cookie’s SameSite setting for these options.

pub fn same_site(Options) -> CookieSameSite

session_ttl

The validated session TTL for these options.

pub fn session_ttl(Options) -> session_ttl.SessionTtl

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
) -> Options

Set whether the session cookie requires HTTPS. See CookieSecurity.

pub fn with_cookie_security(
Options,
CookieSecurity
) -> Options

with_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
) -> Options

with_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