Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
rocket_auth
rocket_auth provides a ready-to-use backend agnostic API for authentication management. For more information visit the documentation at https://docs.rs/rocket_auth. It supports connections for SQLite and Postgresql. It lets you create, delete, and authenticate users. The available features are:
sqlite-db
: for interacting with a SQLite database.postgres-db
: for interacting with a Postgresql database.redis-session
: for storing sessions on a redis server.
By default this crate stores sessions on a concurrent hashmap.
As a result, sessions will only be stored as long as the rocket application runs uninterrupted.
In order to store persistent sessions, it is recommended to connect the Users
(Users::open_redis
) instance to a redis server .
This requires the redis-session
feature to be enabled.
rocket_auth
uses private cookies to store session data.
This means that in order for cookies to be properly decrypted between launches, a secret_key
must be set.
For more information visit rocket's configuration guide.
To use rocket_auth
include it as a dependency in your Cargo.toml file:
[dependencies.rocket_auth]
version = "0.1.2"
features = ["sqlite-db"]
Quick overview
This crate provides two guards:
Auth
: manages authentication.Session
: retrieves session data from client cookies.User
: It restricts content, so it can be viewed by authenticated clients only.
It also includes two structs to be parsed from forms and json data:
Signup
: used to create new users.Login
: used to authenticate users.
Finally it has two structures for queries:
Users
: it allows to query users to the database.User
: it is the response of a query.
The Auth
guard allows to log in, log out, sign up, modify, and delete the currently (un)authenticated user.
For more information see Auth
. Because of rust's ownership rules, you may not retrieve both rocket::http::Cookies
and the Auth
guard
simultaneously. However, retrieveng cookies is not needed since Auth
stores them in the public field Auth::cookies
.
A working example:
use ;
use ;
Users struct
The Users
struct administers interactions with the database.
It lets you query, create, modify and delete users.
Unlike the Auth
guard, a Users
is instance can manage any user in the database.
Note that the Auth
guards includes a Users
instance stored on the public users
field.
So it is not necesary to retrieve Users when using Auth
.
A simple example of how to query a user with the Users
struct:
A Users
instance can be constructed by connecting it to the database with the methods open_sqlite
(Users::open_sqlite),
open_postgres
(Users::open_postgres). Furthermore, it can be constructed from a working connection.