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.
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);git tag -a v0.1.0 -m "Release Message"
git push origin main --follow-tagsEvery contribution to this project is welcome! Feel free to open a pull request or an issue.
Distributed under the terms of both the MIT license and the Apache License (Version 2.0)
