NAME

Uniform::HTTP::Auth::Basic - HTTP Basic authentication construction

SYNOPSIS

use Uniform::HTTP::Auth;
use Uniform::HTTP::Auth::Basic;

my $auth = Uniform::HTTP::Auth->new;
my $challenge = $auth->parse_challenges(
    'Basic realm="Members", charset="UTF-8"'
)->[0];

my $value = Uniform::HTTP::Auth::Basic->authorization(
    username  => 'user',
    password  => 'secret',
    challenge => $challenge,
);

# Basic dXNlcjpzZWNyZXQ=

DESCRIPTION

Uniform::HTTP::Auth::Basic validates Basic challenges and constructs Basic authentication field values according to RFC 7617. It contains no HTTP client, server, retry, or framework behavior.

Most applications will use it through Uniform::HTTP::Auth. The direct API is available when a caller only needs Basic mechanics.

METHODS

validate_challenge

my $error = Uniform::HTTP::Auth::Basic->validate_challenge($challenge);

Returns undef for a structurally usable Basic challenge or a diagnostic string otherwise. A realm is required. If charset is present, the only supported value is UTF-8, matched case-insensitively.

Unknown Basic challenge parameters are preserved by the root parser and ignored by the Basic calculation.

select_challenge

my $challenge = Uniform::HTTP::Auth::Basic->select_challenge(\@basic);

Returns the first usable Basic challenge in wire order, or undef.

authorization

my $value = Uniform::HTTP::Auth::Basic->authorization(
    username  => $username,
    password  => $password,
    challenge => $challenge,
);

Returns the complete field value beginning with Basic .

The username may not contain a colon, and neither username nor password may contain HTTP control characters.

When the challenge contains charset="UTF-8", username and password are normalized to NFC and encoded as UTF-8 before Base64 encoding.

RFC 7617 leaves the default encoding undefined when charset is absent. Version 0.01 therefore accepts ASCII credentials only in that case rather than silently guessing an encoding.

SECURITY NOTES

Basic authentication does not encrypt credentials; Base64 is only an encoding. Use a secure transport such as TLS when the credentials are sensitive.

SEE ALSO

Uniform::HTTP::Auth, RFC 7617.

AUTHOR

Joshua S. Day, <HAX@cpan.org>

LICENSE

This software is released under the MIT License.