The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Parse::WWWAuthenticate - Parse the WWW-Authenticate HTTP header

VERSION

version 0.01

SYNOPSIS

use Parse::WWWAuthenticate qw(parse_wwwa);

my $header = 'Basic realm="test"';
my %challenges = parse_wwwa( $header );
if ( $challenges{Basic} ) {
    print "Need credentials for realm " . $challenges{Basic}->{realm};
}

print "Those challenges are allowed: " . join ', ', sort keys %challenges;

kinda more real life:

use LWP::UserAgent;
use Parse::WWWAuthenticate qw(parse_wwwa);

my $ua       = LWP::UserAgent->new;
my $response = $ua->get('http://some.domain.example');
my $header   = $response->header('WWW-Authenticate');

my %challenges = parse_wwwa( $header );
if ( $challenges{Basic} ) {
    print "Need credentials for realm " . $challenges{Basic}->{realm};
}

print "Those challenges are allowed: " . join ', ', sort keys %challenges;

FUNCTIONS

parse_wwwa

parses the content of the WWW-Authenticate header and returns a hash of all the challenges and their data.

my $header = 'Basic realm="test"';
my %challenges = parse_wwwa( $header );
if ( $challenges{Basic} ) {
    print "Need credentials for realm " . $challenges{Basic}->{realm};
}

print "Those challenges are allowed: " . join ', ', sort keys %challenges;

split_header_words

ACKNOWLEDGEMENTS

The testcases were generated with the httpauth.xml file from https://greenbyte.de/tech/tc/httpauth.

AUTHOR

Renee Baecker <reneeb@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2016 by Renee Baecker.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)