Brize Auth
A tiny async authentication library.
Summary
A tool for simplifying authentication for RESTful ecosystems. Purposefully built to be agnostic of your specific business/schema logic for managing users. Primarily controls the user credentials and optionally managing sessions. Built asynchronously with the Tokio runtime, and supports MySql, SurrealDB, and Redis.
Credentials
Brize auth credentials has 3 fields, an id for linking to your specific business/schema logic, the user_identity which should be a unique way to identify a user such as an email, and a hashed_password. This will be stored in a user_credentials table on your database.
Sessions
The sessions are optional, in case you want to use some other session solution. If you do enable sessions, Brize auth offers classic table sessions, which have an id field as the token, created_at and expired_at for managing the expiration. The sessions will be stored in a user_sessions table on your database. Brize auth also offers JWT session management.
Setup
First install the crate
Next, set up the database tables with this schema, if using a SQL database
-- Credentials table
(
id CHAR(36) PRIMARY KEY,
user_identity VARCHAR(255) NOT NULL,
hashed_password VARCHAR(255) NOT NULL
);
-- Sessions table
(
id CHAR(36) PRIMARY KEY,
created_at BIGINT UNSIGNED NOT NULL,
expires_at BIGINT UNSIGNED NOT NULL
);
Usage
use ;
See the src/examples directory for more information.
Config
The preferred database and session type can be configured to your use case.
use ;
let config = new
// Set your preferred database tech for the credentials table
.set_credentials_gateway
// Set your session type, Session, JWT, or None to disable and the duration
.set_session_type;
// Override the default session GatewayType from above
.set_session_gateway
let auth = new.await;
Supported Databases
- MySql (credentials + sessions)
- SurrealDB (credentials + sessions)
- Redis (sessions only)
Testing
Setup
Install docker and run make sure the daemon is running
Fork this repo
gh repo fork xbrize/brize_auth
Running Tests
All test scripts are in ./scripts but feel free to make your own. You will need to chmod +x to the script files.
After giving permission to execute, simply run them. Each is designed to spin up docker containers that are hosting generic databases. These are then used to run the tests against.
Roadmap
Prototype phase
- User Registration
- Create user credentials if none exist
- Deny if user credentials does exist
- Return credentials foreign key
- Login
- Match user credentials
- Return session token if matched (if sessions enabled)
- Deny user if no match
- Hash password
- Session Management
- Create session
- Validate session
- Delete sessions based on age and logout
- Logout
- Delete users session
- Change Credentials
- Update user_identity
- Update user_password
- Delete User
- Remove credentials and session from database
Alpha testing phase
- Code refactoring
- Domain module
- Application module
- Infrastructure module
- Library
- Live testing
- Secure production db testing
- Benchmarking
- Code Review
Beta features
- Configure custom table names for credentials and sessions
- Configure custom claims for JWT
- Add refresh config for Session and JWT
- Add OAuth