Click here to get back home

LWP and Digest authentication

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
LWP and Digest authentication earwigtc 02-08-2007
Posted by earwigtc on February 8, 2007, 1:50 pm
Please log in for more thread options


Hi all. I must be missing something here. Is LWP supposed to
automatically deal with digest authentication? I run the following
code (used often with basic auth) against a server requiring digest,
and continue to get 401s:

my $ua = new LWP::UserAgent;
my $h = HTTP::Headers->new();
$h->authorization_basic('user','password');
my $req = HTTP::Request->new('GET', 'http://the.website.com',
$h);
my $res = $ua->request($req);

A sniff shows only one attempt to login, and no reaction to the fact
that the server returned a WWW-Authenticate header with the real,
nonce, etc. Do I need to call requests a different way to get the
auto-magical behavior? I'm using htis format because of other needs
(custom headers later).

Since I can't find any discussion or example of digest instead of
basic, I figured it should work. Or do I need to do all the digest
legwork myself?

Thanks.


Posted by Peter Scott on February 9, 2007, 7:42 am
Please log in for more thread options


On Thu, 08 Feb 2007 10:50:08 -0800, earwigtc wrote:
> Hi all. I must be missing something here. Is LWP supposed to
> automatically deal with digest authentication? I run the following
> code (used often with basic auth) against a server requiring digest,
> and continue to get 401s:
>
> my $ua = new LWP::UserAgent;
> my $h = HTTP::Headers->new();
> $h->authorization_basic('user','password');
> my $req = HTTP::Request->new('GET', 'http://the.website.com',
> $h);
> my $res = $ua->request($req);

I don't know what your problem is here or whether my suggestion will make
any difference, but I will point out that the new credentials() method I
added to WWW::Mechanize (1.20 and later) would make your code considerably
simpler:

my $mech = WWW::Mechanize->new;
$mech->credentials('user', 'password');
$mech->get('https://the.website.com/');

> A sniff shows only one attempt to login, and no reaction to the fact
> that the server returned a WWW-Authenticate header with the real,
> nonce, etc. Do I need to call requests a different way to get the
> auto-magical behavior? I'm using htis format because of other needs
> (custom headers later).

You would be able to do this with $mech->add_header.

> Since I can't find any discussion or example of digest instead of
> basic, I figured it should work. Or do I need to do all the digest
> legwork myself?

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


Posted by earwigtc on February 9, 2007, 11:39 am
Please log in for more thread options


I like it. I'm saving info (such as headers_as_string) of the request
object for debugging. I see $mech->response, but is there a way to
reference the request object? Never had to do it with just a
LWP::UserAgent object. Aside from that, I can rework using
WWW::Mechanize just fine.

I would still be interested in a working digest authentication example
with LWP directly, if anyone has one.

Earwig


> On Thu, 08 Feb 2007 10:50:08 -0800, earwigtc wrote:
> > Hi all. I must be missing something here. Is LWP supposed to
> > automatically deal with digest authentication? I run the following
> > code (used often with basic auth) against a server requiring digest,
> > and continue to get 401s:
>
> > my $ua = new LWP::UserAgent;
> > my $h = HTTP::Headers->new();
> > $h->authorization_basic('user','password');
> > my $req = HTTP::Request->new('GET', 'http://the.website.com',
> > $h);
> > my $res = $ua->request($req);
>
> I don't know what your problem is here or whether my suggestion will make
> any difference, but I will point out that the new credentials() method I
> added to WWW::Mechanize (1.20 and later) would make your code considerably
> simpler:
>
> my $mech = WWW::Mechanize->new;
> $mech->credentials('user', 'password');
> $mech->get('https://the.website.com/');
>
> > A sniff shows only one attempt to login, and no reaction to the fact
> > that the server returned a WWW-Authenticate header with the real,
> > nonce, etc. Do I need to call requests a different way to get the
> > auto-magical behavior? I'm using htis format because of other needs
> > (custom headers later).
>
> You would be able to do this with $mech->add_header.
>
> > Since I can't find any discussion or example of digest instead of
> > basic, I figured it should work. Or do I need to do all the digest
> > legwork myself?
>
> --
> Peter Scotthttp://www.perlmedic.com/http://www.perldebugged.com/



Posted by Peter Scott on February 10, 2007, 7:51 am
Please log in for more thread options


On Fri, 09 Feb 2007 08:39:50 -0800, earwigtc wrote:
> I like it. I'm saving info (such as headers_as_string) of the request
> object for debugging. I see $mech->response, but is there a way to
> reference the request object? Never had to do it with just a
> LWP::UserAgent object. Aside from that, I can rework using
> WWW::Mechanize just fine.

http://search.cpan.org/~gaas/libwww-perl-5.805/lib/HTTP/Response.pm:

$r->request
$r->request( $request )
This is used to get/set the request attribute. The request attribute is a
reference to the the request that caused this response. It does not have
to be the same request passed to the $ua->request() method, because there
might have been redirects and authorization retries in between.

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


Posted by Paul Mitchell on February 26, 2007, 10:05 am
Please log in for more thread options


Hello,
Not new to using Perl, but new to trying to install it and use it on a
Windows NT platform. Doing this in order to load Andy Duncans Oracle/Perl
modules. Got PPM running and want, basically to do as follows:

        ppm install PDBA

According to the instructions, entering "ppm" should give me a
commandline. It doesn't, I get a GUI interface. OK. UNfortunately, search
seems to direct me only to the ActiveState repositories.

How do I get to either the command line PPM, or direct the GUI to look
inthe current directory and not up at ActiveState?

Thanks for any help,

Paul Mitchell




Similar ThreadsPosted
authentication October 31, 2005, 3:32 am
LWP Problems (Authentication?) September 5, 2004, 7:12 am
lwp authentication on asp page March 23, 2005, 10:28 pm
SSL Authentication using Net::POP3 June 25, 2006, 4:40 pm
WWW::Mechanize and NTLM authentication December 21, 2004, 3:55 pm
Net::SSH::Perl Trouble with publickey authentication May 30, 2005, 3:58 am
Apache+MySQL+htaccess - nxt steps after authentication May 26, 2005, 2:01 pm
Perl DBI/DBD MySQL User Authentication Error June 10, 2006, 2:12 pm
[ANN] Digest::SHA 5.28 (w/ shasum) November 18, 2004, 12:50 pm
Module Digest:SHA June 12, 2006, 8:00 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap