in reply to Re: LWP and Digest Authentication
in thread LWP and Digest Authentication

My understanding is that get_basic_credentials() is for Basic Authentication?

And for Digest Authentication one needs to use credentials per the example at LWPTut#HTTP_Authentication?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^3: LWP and Digest Authentication
by ikegami (Patriarch) on Feb 11, 2009 at 02:46 UTC

    It applies to digest as well. I use the following in one of my programs for a site that uses digest:

    sub get_basic_credentials { my ($self, $realm, $uri, $isproxy) = @_; if ( !$isproxy && $realm eq 'example' && $uri->host_port() =~ /(^|\.)example\.com:80\z/i ) { return ($self->{user}, $self->{passwd}); } return $self->SUPER::get_basic_credentials($realm, $uri, $isproxy); }

    credentials populates a hash which the base get_basic_credentials accesses. That's fine for most uses. If it isn't, overridding get_basic_credentials gives extra flexibility. In my case, the realm is fixed, but there's an unlimited number of subdomains being accessed.

        No, it's available as an argument. But you shouldn't even have to look at it unless you wish to limit sending the credentials to a specific realm.
        sub get_basic_credentials { my ($self, $realm, $uri, $isproxy) = @_; if ($uri->host_port() eq =~ /^(?:www\.)?example\.com:80\z/i) { return ($self->{user}, $self->{passwd}); } return $self->SUPER::get_basic_credentials($realm, $uri, $isproxy); }
        No. Notice I don't call the base class's get_basic_credentials for the domain of interest, so the info I would feed to credentials would never get used.