rocketauth provides a ready-to-use backend agnostic API for authentication management.
For more information visit the documentation at https://docs.rs/rocketauth.
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:
ini
[dependencies.rocket_auth]
version = "0.1.3"
features = ["sqlite-db"]
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:
```rust,norun
use rocket::{get, post, Form};
use rocketauth::{Users, Error, Auth, Signup, Login};