#http #auth #basic #credentials #scheme

http-auth-basic

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

7 releases

0.2.2 Jul 14, 2021
0.2.1 Jul 14, 2021
0.1.3 Apr 27, 2021
0.1.2 Sep 17, 2020
0.1.0 Aug 30, 2020

#32 in Authentication

Download history 282/week @ 2021-04-04 300/week @ 2021-04-11 288/week @ 2021-04-18 361/week @ 2021-04-25 274/week @ 2021-05-02 386/week @ 2021-05-09 424/week @ 2021-05-16 592/week @ 2021-05-23 365/week @ 2021-05-30 479/week @ 2021-06-06 559/week @ 2021-06-13 514/week @ 2021-06-20 499/week @ 2021-06-27 441/week @ 2021-07-04 737/week @ 2021-07-11 549/week @ 2021-07-18

1,852 downloads per month
Used in 3 crates

MIT/Apache

26KB
152 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

~220KB