https://github.com/estebanborai/http-auth-basic
HTTP Basic Authentication Scheme (RFC 7617 and RFC 2617 compilant, base64-encoded credentials) for Rust applications
https://github.com/estebanborai/http-auth-basic
auth base64 basic http rust
Last synced: 5 months ago
JSON representation
HTTP Basic Authentication Scheme (RFC 7617 and RFC 2617 compilant, base64-encoded credentials) for Rust applications
- Host: GitHub
- URL: https://github.com/estebanborai/http-auth-basic
- Owner: EstebanBorai
- License: apache-2.0
- Created: 2020-08-30T22:02:28.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-28T02:36:05.000Z (12 months ago)
- Last Synced: 2025-01-22T20:06:53.256Z (6 months ago)
- Topics: auth, base64, basic, http, rust
- Language: Rust
- Homepage: https://crates.io/crates/http-auth-basic
- Size: 43.9 KB
- Stars: 10
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- Contributing: CONTRIBUTING.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
![]()
http-auth-basic
HTTP Basic Authentication Scheme (RFC 7617 and RFC 2617 compilant, base64-encoded credentials) for Rust applications
[](https://crates.io/crates/http-auth-basic)
[](https://docs.rs/http-auth-basic)




## Description
The "Basic" Hypertext Transfer Protocol (HTTP) authentication scheme, transmits credentials as user-id/password pairs, encoded using Base64.
![]()
The server will gather the credentials from the base64 encoded header value, and will validate them
to authenticate the user in question.This crate covers the credentials encoding and decoding. The `Credentials` struct provides two fields
`user_id` and `password`, these are filled with they raw values.## Usage
Decoding a basic authorization value and creating a `Credentials` struct
from it```rust
use http_auth_basic::Credentials;let auth_header_value = String::from("Basic dXNlcm5hbWU6cGFzc3dvcmQ=");
let credentials = Credentials::from_header(auth_header_value).unwrap();assert_eq!(credentials.user_id, String::from("username"));
assert_eq!(credentials.password, String::from("password"));
```Encoding `Credentials` into a basic authorization header value.
```rust
use http_auth_basic::Credentials;let credentials = Credentials::new("username", "password");
let credentials = credentials.as_http_header();assert_eq!(String::from("Basic dXNlcm5hbWU6cGFzc3dvcmQ="), credentials);
```## Release
```bash
git tag -a v0.1.0 -m "Release Message"
git push origin main --follow-tags
```## Contributing
Every contribution to this project is welcome! Feel free to open a pull request or an issue.
## References
- [MDN The general HTTP Authentication Framework](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication)
- [RFC7617](https://tools.ietf.org/html/rfc7617)
- [RFC2617](https://tools.ietf.org/html/rfc2617)## License
Distributed under the terms of both the MIT license and the Apache License (Version 2.0)