pub struct Builder { /* private fields */ }
Expand description

You can use multiple authentication setups on a single site, but make sure that the respective Builder::with_cookie_paths do not overlap. You MUST set with_cookie_path to use more than 1 auth setup.

Implementations

Create a new builder. Use Self::build or Self::build_validate to get a Config.

Sets the URL endpoint where your frontend authenticates to.

Decrease security and protection against CSRF but allow users to follow links to auth-protected pages from other sites. This sets the SameSite property of the cookie to lax.

Decrease security and protection against XSS but allow the JavaScript to read the cookie, which allows the client to get the logged in status. It’s highly recommended to enable Builder::with_force_relog_on_ip_change when this is enabled, as that negates any credential theft, as the credentials are bound to an IP.

This disables the usual setting of the HttpOnly cookie property. This does not affect the credentials cookie. That will never be served without HttpOnly.

Forces relogging by the user when they change IPs. This can protect users from getting their cookies scraped by malware, as the authentication is IP dependant.

Sets the name of the JWT cookie. This is the cookie that authorizes the user.

Panics

Panics if jwt_cookie_name contains illegal bytes for a header value.

Sets the name of the credentials cookie. This is the cookie that stores the user’s credentials to allow renewal of the JWT cookie without requiring the user to input credentials. It is encrypted with the server’s PK.

Panics

Panics if credentials_cookie_name contains illegal bytes for a header value.

Sets the path of all the cookies. Set this to avoid slowing down other pages on your server, as Kvarn will try to renew the JWT on every page by default. By setting this to only your protected pages, the JWT cookie is only sent there. Kvarn thinks the user isn’t logged in on other pages, reducing the work it has to do.

This is also useful if you want to have multiple authentication systems on a single host.

Panics

Panics if cookie_path contains illegal bytes for a header value.

Show this page when the user isn’t logged in.

This guarantees nobody can view any pages which starts with Self::with_cookie_path without being logged in.

Please also specify Self::with_cookie_path, as else auth_page will be shown instead of every other page when not logged in.

Panics

Panics if show_auth_page_when_unauthorized cannot be converted into a kvarn::prelude::HeaderValue. kvarn::prelude::Uri.

Makes all JWTs valid for the duration of valid_for. After that, the JWT is automatically refreshed from the securely stored credentials.

Makes the credentials cookie valid for the duration of valid_for. If this is a year, the user doesn’t have to relog in a year.

Build these settings into a Config, which you then use for validation.

Available on crate features rsa or ecdsa only.

Build these settings into a Config built for validation. See the module-level documentation for more info.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.