Skip to main content

Module auth

Module auth 

Source
Expand description

Authorization, Proxy-Authorization, WWW-Authenticate, and Proxy-Authenticate (RFC 9110 section 11), with the Bearer (RFC 6750) and Basic (RFC 7617) payloads.

Credentials are secrets: Debug on Credentials and AuthPayload prints the scheme and parameter names only.

§Examples

use parse_net::{self as pn, auth, Limits};

assert_eq!(pn::bearer(b"bearer  mF_9.B5f-4.1JqM==")?, Some(&b"mF_9.B5f-4.1JqM=="[..]));
assert_eq!(pn::bearer(b"Basic dXNlcjpwYXNz")?, None);
assert_eq!(pn::basic(b"Basic dXNlcjpwYXNz")?, Some(&b"dXNlcjpwYXNz"[..]));

let c = auth::parse_credentials(b"Digest username=\"a\", realm=\"r\"", &Limits::DEFAULT)?;
assert!(c.scheme_is("digest"));
assert_eq!(format!("{c:?}"), "Credentials { scheme: \"Digest\", .. }");

Structs§

AuthParams
Comma-separated auth-params, validated.
Challenge
One challenge.
ChallengeIter
The challenges of a validated value.
Challenges
Validated challenges.
Credentials
Validated credentials (Authorization, Proxy-Authorization).

Enums§

AuthPayload
What follows the scheme of a credential or a challenge.

Functions§

basic
The base64 text of a Basic Authorization value (RFC 7617): Some when the scheme is Basic, None for another scheme. The text is checked (the base64 alphabet, padding only at the end, a length that is a multiple of four) and not decoded.
bearer
The Bearer token of an Authorization value (RFC 6750 section 2.1): Some(token) when the scheme is Bearer (case-insensitive), None for another scheme.
parse_challenges
Parses WWW-Authenticate or Proxy-Authenticate: #challenge.
parse_credentials
Parses credentials = auth-scheme [ 1*SP ( token68 / #auth-param ) ].
write_challenge
Writes a challenge with parameters: Bearer realm="api", error="invalid_token". realm is always quoted (RFC 9110 section 11.5); other values are tokens when they can be.
write_challenge_token68
Writes a challenge with a token68: Negotiate <token68>.