http://www.perlmonks.org?node_id=901913

jaldhar has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a script that uses WWW::Mechanize. I need to do basic and WSSE UserToken authentication. The former is easy. For the latter I found LWP::Authen:Wsse on CPAN. WWW::Mechanize is a subclass of LWP::UserAgent so I should be able to use it right? Only, I can't figure out how. Here is some sample code:

#!/usr/bin/perl use warnings; use strict; use WWW::Mechanize; use LWP::Authen::Wsse; my $mech = WWW::Mechanize->new; $mech->credentials('username', 'password'); # some debug stuff. $mech->default_header('Accept-Encoding' => scalar HTTP::Message::decod +able()); $mech->add_handler("request_send", sub { shift->dump; return }); $mech->add_handler("response_done", sub { shift->dump; return }); $mech->get('http://localhost/');

Note that no method from LWP::Authen::Wsse is called in the script. That's because according to the modules' documentation:

The module is used indirectly through LWP, rather than including it directly in your code. The LWP system will invoke the WSSE authentication when it encounters the authentication scheme while attempting to retrieve a URL from a server.

I think this is where I'm going wrong. Is the server supposed to send a special header asking for WSSE authentication like it does for Basic Auth? Or does LWP::Auth::Wsse (which only has one method called authenticate) have to be injected into a WWW::Mechanize object somehow? I see that LWP::UserAgent in the request() method has a hook to call authenticate() but I can't seem to get from A to B. Help!

--
જલધર