Skip to main content

auth

Function auth 

Source
pub fn auth() -> AuthLayer
Expand description

Middleware that enforces authentication, for any tower stack: axum, tonic or hyper.

Completes Stackure’s sign-in handoff by validating the posted session_token and storing it as a cookie on your domain. On success the user is inserted into the request extensions (read it back with user_from_request). Browser requests get redirected to sign-in on 401, and to a Stackure page that says sign-in couldn’t be confirmed when the check fails; API requests get JSON.

On localhost or 127.0.0.1 with the app’s development secret, sign-in returns to the page that asked for it: Stackure posts a one-time code there, and the layer swaps it for a session using the secret and a check value it keeps in a cookie. Only app admins of the organization that added the app can sign in this way.

§Example

let app = app.layer(stackure::auth());