rocket-basicauth

A high-level basic access authentication request guard for Rocket.rs

4 stable releases

3.0.0 Jan 3, 2024
2.1.1 Sep 7, 2021
1.0.0 Dec 2, 2020
Download history 278/week @ 2024-07-22 251/week @ 2024-07-29 161/week @ 2024-08-05 236/week @ 2024-08-12 147/week @ 2024-08-19 63/week @ 2024-08-26 196/week @ 2024-09-02 102/week @ 2024-09-09 195/week @ 2024-09-16 364/week @ 2024-09-23 285/week @ 2024-09-30 379/week @ 2024-10-07 338/week @ 2024-10-14 411/week @ 2024-10-21 236/week @ 2024-10-28 409/week @ 2024-11-04

1,394 downloads per month
Used in 3 crates

MIT license

11KB
93 lines

rocket-basicauth

Tests Docs

A high-level basic access authentication request guard for Rocket.rs

Example

#[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])
}

Installation

Simply add the following to your Cargo.toml file:

[dependencies]
rocket-basicauth = "3"

Disabling logging

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 }

Rocket 0.5-rc1 to 0.5-rc3

Version 2.0 supports the pre-release versions of Rocket 0.5 RC1 to RC3

[dependencies]
rocket-basicauth = "2"

Rocket 0.4

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"

Security

Some essential security considerations to take into account are the following:

  • This crate has not been audited by any security professionals. If you are willing to do or have already done an audit on this crate, please create an issue as it would help out enormously! 😊
  • This crate purposefully does not limit the maximum length of http basic auth headers arriving so please ensure your webserver configurations are set properly.

Dependencies

~15–46MB
~792K SLoC