Crates.io | rocket-basicauth |
lib.rs | rocket-basicauth |
version | 3.0.0 |
source | src |
created_at | 2020-12-02 17:43:51.712541 |
updated_at | 2024-01-03 23:49:25.123396 |
description | A high-level basic access authentication request guard for Rocket.rs |
homepage | |
repository | https://github.com/owez/rocket-basicauth |
max_upload_size | |
id | 318964 |
size | 12,039 |
A high-level basic access authentication request guard for Rocket.rs
#[macro_use] extern crate rocket;
use rocket_basicauth::BasicAuth;
/// Hello route with `auth` request guard, containing a `name` and `password`
#[get("/hello/<age>")]
fn hello(auth: BasicAuth, age: u8) -> String {
format!("Hello, {} year old named {}!", age, auth.username)
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![hello])
}
Simply add the following to your Cargo.toml
file:
[dependencies]
rocket-basicauth = "3"
By default, this crate uses the log
library to automatically add minimal trace-level logging, to disable this, instead write:
[dependencies]
rocket-basicauth = { version = "2", default-features = false }
Version 2.0 supports the pre-release versions of Rocket 0.5 RC1 to RC3
[dependencies]
rocket-basicauth = "2"
Support for Rocket 0.4 is decrepit in the eyes of this crate but may still be used by changing the version, to do this, instead write:
[dependencies]
rocket-basicauth = "1"
Some essential security considerations to take into account are the following: