rocket_auth provides a ready-to-use backend agnostic API for authentication management.
It supports connections for SQLite and Postgresql. It lets you create, delete, and authenticate users.
The available features are:
* sqlx-sqlite
: for interacting with a SQLite database using sqlx
.
* sqlx-postgres
: for interacting with a Postgresql database with sqlx
.
* sqlx-mysql
: for interacting with a MySql database with sqlx
.
* redis
: for storing sessions on a redis server using redis
.
* rusqlite
: for interacting with a SQLite database using rusqlite
.
* tokio-postgres
: for interacting with a Postgresql database with tokio-postgres
.
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.4.0"
features = ["sqlx-sqlite"]
This crate provides three guards:
* Auth
: Manages authentication.
* Session
: It's used to retrieve 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
.
A working example:
```rust
use rocket::{get, post, form::Form, routes};
use rocket_auth::{Users, Error, Auth, Signup, Login};