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

I am trying to request a page that requires 2 different sets of authentication for 2 different realms. Sending the Basic Authorization in the header works for the first set however I can not get the credentials to pass for the second realm.
$uri = "HTTPS://$host:$port/path"; $ua = new LWP::UserAgent; $h = new HTTP::Headers; $h->header('Authorization' => "Basic $authinfo"); $request = new HTTP::Request('POST', $uri, $h, $content); $ua->credentials("$host:$port",'realm2',$userid,$password); $response = $ua->request($request); print $response->status_line; print $response->as_string;
When the ua->credentials line is included the authentication doesn't even work for the first realm. If that is excluded the first realm authenticates but the second realm fails. Is there a way of sending 2 sets of credentials for 2 different realms.

Replies are listed 'Best First'.
Re: Authenticating against multiple realms
by shmem (Chancellor) on Sep 25, 2006 at 21:29 UTC

    It's not quite clear what you are trying to do. The credentials of $ua->credentials() are not sent by the code you provide - they don't show up in the POST request packet.

    What are 'first' and 'second' realm here, and at which moment what credentials are requested? In what $authinfo and $userid,$password are different, what is the purpose of each?

    AFAIK there's only one realm ever associated with a particular URI; if you have two realms to authenticate to, there must be two requests also, but I might be wrong.

    If the 'second realm' authentication request is triggered by the handler of the first request, you might have to include the $realm, $userid, $password in $content of the POST.

    A bit more explanation about the whole thing would help to help, specially the response of the server with/without Authorization: header line, i.e. status and headers.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}