Giter VIP home page Giter VIP logo

rocket-basicauth's Introduction

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.

rocket-basicauth's People

Contributors

markeel avatar owez avatar schnippl0r avatar timothynewton avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rocket-basicauth's Issues

Incompatible with rocket-0.5.0-rc.4

Full changelog

I guess these is the relevant changes:

Route Forward outcomes are now associated with a Status.
Outcome::Failure was renamed to Outcome::Error.

error[E0308]: mismatched types
Error:    --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocket-basicauth-2.1.1/src/lib.rs:166:35
    |
166 |             0 => Outcome::Forward(()),
    |                  ---------------- ^^ expected `Status`, found `()`
    |                  |
    |                  arguments to this enum variant are incorrect
    |
help: the type constructed contains `()` due to the type of the argument passed
   --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocket-basicauth-2.1.1/src/lib.rs:166:18
    |
166 |             0 => Outcome::Forward(()),
    |                  ^^^^^^^^^^^^^^^^^--^
    |                                   |
    |                                   this argument influences the type of `Outcome`
note: tuple variant defined here
   --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocket-0.5.0-rc.4/src/outcome.rs:111:5
    |
111 |     Forward(F),
    |     ^^^^^^^

error[E0599]: no variant or associated item named `Failure` found for enum `Outcome` in the current scope
Error:    --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocket-basicauth-2.1.1/src/lib.rs:169:34
    |
169 |                 None => Outcome::Failure((Status::BadRequest, BasicAuthError::Invalid)),
    |                                  ^^^^^^^ variant or associated item not found in `Outcome<_, _, _>`

error[E0599]: no variant or associated item named `Failure` found for enum `Outcome` in the current scope
Error:    --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocket-basicauth-2.1.1/src/lib.rs:171:27
    |
171 |             _ => Outcome::Failure((Status::BadRequest, BasicAuthError::BadCount)),
    |                           ^^^^^^^ variant or associated item not found in `Outcome<_, _, _>`

Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `rocket-basicauth` (lib) due to 3 previous errors
Error: warning: build failed, waiting for other jobs to finish...
Error: The process '/home/runner/.cargo/bin/cargo' failed with exit code 101

Remove fmt_id

Useless bit that wasn't picked up because of the logging cfg guard

how is this intended to be used?

I just want to add basic auth with a fixed password to a simple rocket app for demo purposes.

The example doesn't include a route to prompt for a basic auth username/password, and I'm actually unable to get that working seemingly because working with forward catchers in rocket 0.5 seems to be completely undocumented. Should this not be part of the crate?

was expecting it to automatically respond with the proper WWW-Authenticate header when unauthenticated and have an easy way of doing this when password/username is incorrect. I am perplexed how people are using this without that

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.