Skip Menu |

This queue is for tickets about the libwww-perl CPAN distribution.

Report information
The Basics
Id: 12967
Status: resolved
Priority: 0/
Queue: libwww-perl

People
Owner: Nobody in particular
Requestors: jaime [...] bellmyer.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: LWP UserAgent Credentials
Hello- I was working with LWP::UserAgent yesterday, when I discovered that using the credentials method with basic authentication required me to know the exact realm. I modified my copy of LWP/UserAgent.pm so that will accept a default realm, and it works great. I'm submitting this because I think it would be a great addition to the module. My code (just 2 extra lines) first performs the traditional hash check for a realm match, but then checks for a blank realm to use as a default. Original code (in get_basic_credentials): if (exists $self->{'basic_authentication'}{$host_port}{$realm}) { return @{ $self->{'basic_authentication'}{$host_port}{$realm} }; } Updated code: if (exists $self->{'basic_authentication'}{$host_port}{$realm}) { return @{ $self->{'basic_authentication'}{$host_port}{$realm} }; } elsif (exists $self->{'basic_authentication'}{$host_port}{''}) { return @{ $self->{'basic_authentication'}{$host_port}{''} }; } More readable version (I think): for ($realm, '') { if (exists $self->{'basic_authentication'}{$host_port}{$_}) { return @{ $self->{'basic_authentication'}{$host_port}{$_} }; } } The blank realm ('') could be replaced by some other default ('*', for instance). If you think this would be a good addition, please add it. By the way, what does it take to officially become an "author" of this module? Thanks, Jaime Bellmyer
On Thu May 26 15:27:05 2005, guest wrote: Show quoted text
> Hello- > > I was working with LWP::UserAgent yesterday, when I discovered that > using the credentials method with basic authentication required me to > know the exact realm. I modified my copy of LWP/UserAgent.pm so that > will accept a default realm, and it works great. I'm submitting this > because I think it would be a great addition to the module. > > My code (just 2 extra lines) first performs the traditional hash check > for a realm match, but then checks for a blank realm to use as a > default. > > Original code (in get_basic_credentials): > > if (exists $self->{'basic_authentication'}{$host_port}{$realm}) { > return @{ $self->{'basic_authentication'}{$host_port}{$realm} }; > } > > Updated code: > > if (exists $self->{'basic_authentication'}{$host_port}{$realm}) { > return @{ $self->{'basic_authentication'}{$host_port}{$realm} }; > } elsif (exists $self->{'basic_authentication'}{$host_port}{''}) { > return @{ $self->{'basic_authentication'}{$host_port}{''} }; > } > > More readable version (I think): > > for ($realm, '') > { > if (exists $self->{'basic_authentication'}{$host_port}{$_}) { > return @{ $self->{'basic_authentication'}{$host_port}{$_} }; > } > } > > The blank realm ('') could be replaced by some other default ('*', for > instance). If you think this would be a good addition, please add it. > By the way, what does it take to officially become an "author" of this > module? > > Thanks, > > > Jaime Bellmyer
I can only imagine this is coming far, far too late, but this can be done via: my $req = HTTP::Request->new('GET', 'https://www.foo.com'); $req->authorization_basic('username', 'password'); OR my $res = $ua->get('https://username:password@www.foo.com'); Olaf