Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pepsighan/basic-auth-raw
A base for Basic Authentication over which a concrete authentication mechanism can be built
https://github.com/pepsighan/basic-auth-raw
basic-authentication rocket-rs
Last synced: about 2 months ago
JSON representation
A base for Basic Authentication over which a concrete authentication mechanism can be built
- Host: GitHub
- URL: https://github.com/pepsighan/basic-auth-raw
- Owner: pepsighan
- License: mit
- Created: 2018-04-17T13:59:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-16T09:38:07.000Z (over 6 years ago)
- Last Synced: 2024-04-23T08:07:43.545Z (8 months ago)
- Topics: basic-authentication, rocket-rs
- Language: Rust
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Raw Basic Authentication
A [Rocket](https://github.com/SergioBenitez/Rocket) library to provide a base for
Basic Authentication over which a concrete authentication mechanism can be built.This library exports `BasicAuthRaw` which you could directly use on the request handler.
#### Example```rust
use basic_auth_raw::BasicAuthRaw;#[get("/secure-path")
fn secret(basic: BasicAuthRaw) -> String {
format!("Your username is {}", basic.username);
}
```Or you could build Request Guards on top of it (Recommended).
#### Example```rust
use basic_auth_raw::BasicAuthRaw;struct Admin(User);
impl<'a, 'r> FromRequest<'a, 'r> for Admin {
type Error = ();fn from_request(request: &Request) -> Outcome {
let basic = BasicAuthRaw::from_request(request)?;
let user = User::from_db(basic.username, basic.password);
if user.is_admin {
Outcome::Success(user);
} else {
Outcome::Failure((Status::Unauthorized, ()));
}
}
}#[get("/secure-path")
fn secret(admin: Admin) -> String {
format!("Your username is {}", admin.user.username);
}
```