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

I am trying to interface with our Scalix server's CalDAV implementation (http://www.scalix.com/wiki/index.php?title=TB/TB-2008-01-CALDAV) using HTTP::DAV. I am getting hung up early on with an authentication problem. The debugging output looks like the login details I set are being overridden. Here's my code (with actual server names, login details changed):
#!/usr/bin/perl -w use strict; use HTTP::DAV; $\ = "\n"; my $uid = 'foo'; my $pwd = 'bar'; my $url = 'http://my.server.com/api/dav/Calendars/Users/Foo.User@server.com/Cale +ndar'; my $d = new HTTP::DAV; $d->DebugLevel( 3 ); $d->credentials( -user => $uid, -pass => $pwd, -url => $url ); $d->open( -url => $url ) or die "Couldn't open $url: " . $d->message();
And here's the output:
Setting auth details for my.server.com:80, default to 'foo', 'bar' new_resource: For http://my.server.com/api/dav/Calendars/Users/Foo.User@server.com/Calen +dar/, creating new resource Resetting user and password for my.server.com:80, Scalix User Using user/pass combo: . For Scalix User, http://my.server.com/api/dav/Calendars/Users/Foo.User@server.com/Calen +dar/ Couldn't open http://my.server.com/api/dav/Calendars/Users/Foo.User@server.com/Calen +dar: Unauthorized. at ./check_Cal.pl line 33.
It looks like it is changing the login cred to "Scalix User" for some reason. I am fairly new to DAV, and am wondering if the server causing this somehow, or if my code simply bites.

Thanks,
Mike

Replies are listed 'Best First'.
Re: HTTP::DAV changing auth creds?
by almut (Canon) on Jun 09, 2009 at 14:15 UTC

    A quick look at the sources makes me think you might want to try adding a trailing slash to the $url.

    There's some code in ->open() which makes sure there is a trailing slash (which you can also see in the debug output), and as the URL string is being used to index associated resources (like the credentials) via hash lookup, I suppose you're getting two independent resource objects...  Just an idea.

    ("Scalix User" is the login realm, btw, not the user:pass combo. The latter is empty for the URL with the trailing slash.)

      Hmmm... The trailing slash didn't change things. Thanks for the tip regarding the realm, though. Unfortunately, adding that to the credentials method didn't change things.
Re: HTTP::DAV changing auth creds?
by 23skiddoo (Beadle) on Jun 10, 2009 at 15:57 UTC
    Grrr... I've got the authentication to work, but I am now getting "Internal Server Error" responses. The URLs I am trying work just fine when entered in a browser. :(
      Hi there, I'm working on this issue, there's a ticket already opened in the bug tracker for HTTP::DAV. I believe at least 2 tickets have to do with this problem now. The code you posted will help me in trying to reproduce the problem and eventually fix it, I hope, so thank you.
        Hi , I am trying to get HTTP::DAV (v0.31) to connect to a https: site which is Dav enabled. The client that I am connecting from is HP-UX. Though I set the password using the credential() method, the program is giving an authetication failure. Please let me know 1) Is there some configuration in the Client side that needs to be set to enable the correct credentials 2)Is version 0.31 having a bug which does not allow the connection to happen TIA Raj
      How did you get the Auth to work? I am having same issue. Please help. Thanks -Laks

        Are you specifying the realm? I've been debugging the code for a while here and the problem (or my problem anyways) is this:

        I specify my credentials like this:

        credentials( -user => 'username', -pass => 'password', -url => 'http://localhost' )

        Now, credentials get stored in a hash like this:

        { 'netloc' => { 'realm' => [ 'username', 'password' ] } }

        By setting the credentials without a realm, it puts them under the default realm, so we end up with:

        { 'localhost' => { 'default' => [ 'username', 'password' ] } }

        The problem is that for some reason after connecting, it discovers the realm name and decides to populate the hash above with an empty set of credentials for the realm:

        { 'localhost' => { 'default' => [ 'username', 'password' ], 'YOUR_REALM' => [ ] } }

        When it goes to retrieve the credentials, it goes in this order:

        { netloc }{ realm } { default }{ realm } { netloc }{ default }

        Since it entered blank credentials for the netloc+realm combination, it grabs those first. Seems like there's something wrong, it probably shouldn't be entering in the blank credentials.