#basic-authentication #basic-auth #base64 #http #http-header #credentials

http-auth-basic

HTTP Basic Authentication Scheme (RFC 7617 and RFC 2617 compilant, base64-encoded credentials) for Rust applications

13 releases

0.3.5 Jul 28, 2024
0.3.4 Jul 28, 2024
0.3.3 Mar 30, 2022
0.3.1 Aug 15, 2021
0.1.0 Aug 30, 2020

#61 in Authentication

Download history 3623/week @ 2024-08-11 4436/week @ 2024-08-18 4371/week @ 2024-08-25 4412/week @ 2024-09-01 4865/week @ 2024-09-08 3393/week @ 2024-09-15 4051/week @ 2024-09-22 5060/week @ 2024-09-29 4862/week @ 2024-10-06 5162/week @ 2024-10-13 4860/week @ 2024-10-20 4018/week @ 2024-10-27 4242/week @ 2024-11-03 5315/week @ 2024-11-10 4561/week @ 2024-11-17 4213/week @ 2024-11-24

18,577 downloads per month
Used in 5 crates

MIT/Apache

28KB
189 lines

http-auth-basic

HTTP Basic Authentication Scheme (RFC 7617 and RFC 2617 compilant, base64-encoded credentials) for Rust applications

Crates.io Documentation Build Clippy Fmt Release Tests

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

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.

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

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

License

Distributed under the terms of both the MIT license and the Apache License (Version 2.0)

Dependencies

~235KB