Tags:
create new tag
view all tags

SID-00793: Perl code to call TWiki URL, HTTPS/SSL, with authentication

Status: Unanswered Unanswered TWiki version: 4.3.0 Perl version: 5.10.0
Category: CategoryAuthentication Server OS: Windows Server 2003 R2 Last update: 15 years ago

Request Perl code sample to invoke TWiki URL using HTTPS/SSL and handle the username/password prompt?

I'm using TWiki Version 4.3.0. Rev 17948 dated 30 March 2009.

Does anyone please have a working Perl code example of calling the twiki URL, using https/ssl, with support for the twiki's username/password prompt?

Hi. I am trying to invoke a module 'viewfile" from my perl program. The twiki is configured to use https (SSL), so I have to use the "LWP::UserAgent" rather than the simpler "HTTP::Request". Regardless of how I set the credentials, it has no effect. I don't get past the username/password prompt.

I tried to add this to the end of the request URL, but it had no effect: ;authorization='base64EncodingOfUsernamePassword'

(I am using the latest ActivePerl, version 1007, which corresponds to Perl version 5.10.1, on the client-side. I am running on a pc with Windows NT.)

Here is the Perl code I am using:

use LWP::UserAgent;
use LWP 5.66;
my $browser = LWP::UserAgent->new;


# this doesn't have any effect:
$browser->credentials( 'k2d.aag.dese.com:443', 'MyRealm', 'KitLueder' => 'password' );


my $url = 'https://k2d.aag.dese.com/twiki/bin/viewfile/Main/OACSIM_MILCON/W91quz07D0004F708?filename=OACSIM_MILCON_System_Capabilities_Mapping.xlsx;rev=5;' ;
my $response = $browser->get($url);
die "Error at $url\n ", $response->status_line, "\n Aborting"
unless $response->is_success;
print "Whee, it worked! I got that ",
$response->content_type, " document!\n";

# I then want to use this to download the resulting file, but it just obtains the username/password prompt screen:
my $datafile = "Filename.doc";
use HTTP::Request::Common;
$response = $browser->request( GET($url), $datafile );
exit;


By the way, the twiki "LocalSite.cfg" file had a strange configuration for AuthRealm, a value of the following: 'Enter your LoginName. (Typically First name and last name, no space, no dots, capitalized, e.g. JohnSmith, unless you chose otherwise). Visit TWikiRegistration if you do not have one.'

To summarize the questions:

1. Request for code example to access twiki using https/ssl, to get past the username/password prompt.

2. Recommendations for how to do the basic authentication credentials, given that we are accessing via ssl.

3. Suggestions of changes

4. How do I query what the host domain and realm are?

5. Does twiki ignore that AuthRealm setting?

Here is another try, which results in HTTP 302 Found Redirect, rather than HTTP 200. But it still doesn't get past the login/password challenge.

I'm using TWiki Version 4.3.0. Rev 17948 dated 30 March 2009.

Does anyone please have a working Perl code example of calling the

twiki URL, using https/ssl, with support for the twiki's username/

password prompt?

Hi. I am trying to invoke a module 'viewfile" from my perl program.

The twiki is configured to use https (SSL), so I have to use the

"LWP::UserAgent" rather than the simpler "HTTP::Request". Regardless

of how I set the credentials, it has no effect. I don't get past the

username/password prompt.

If I put the credentials on the end of the request URL, I get an HTTP

302 Found (redirect) response. I was hoping that meant that the

authentication had succeeded, but the next attempt still triggered a

login prompt anyway.

(I am using the latest ActivePerl, version 1007, which corresponds to

Perl version 5.10.1, on the client-side. I am running on a pc with

Windows NT.)

Here is the Perl code I am using. The first connection attempt

succeeds and gives a 302 response (FOUND redirect), and does not

prompt for username/password. The second connection attempt succeeds

and gives a 200 (success) response, but it still prompts for username/

password.

I don't succeed in downloading the actual requested file.

Here is the code:

#!/usr/bin/perl -w

use LWP::Simple;

use LWP::UserAgent;

# $url2 has credentials, $url does not. Otherwise the same path.

my $url2 = 'https://k2d.aag.dese.com/twiki/bin/viewfile/Main/OACSIM_MILCON/W91quz07D0004F708?filename=OACSIM_MILCON_System_Capabilities_Mapping.xlsx;rev=5;username=KitLueder;password=xxxxxxxxxx';

# First try the url with credentials.

use LWP 5.66;

my $browser = LWP::UserAgent->new;

my $response = $browser->get($url2);

my $responseCode2 = $response->code;

# See if we got a 302 "Found" redirect.

print "RespCode 1stGet:", $responseCode2, "\n";

print "RespHeader URI:", $response->header('URI'), "\n";

print "RespHeader WWWAuth:", $response->header('WWW-Authenticate'), "\n";

print "RespHeader Server:", $response->header('Server'), "\n";

print "RespHeader Location:", $response->header('Location'), "\n";

# Now retry the url without credentials.

my $url = 'https://k2d.aag.dese.com/twiki/bin/viewfile/Main/OACSIM_MILCON/W91quz07D0004F708?filename=OACSIM_MILCON_System_Capabilities_Mapping.xlsx;rev=5;' ;

$response = $browser->get($url);

my $responseCode = $response->code;

print "RespCode:", $responseCode, "\n";

print "RespHeader URI:", $response->header('URI'), "\n";

print "RespHeader WWWAuth:", $response->header('WWW-Authenticate'), "\n";

print "RespHeader Server:", $response->header('Server'), "\n";

print "RespHeader Location:", $response->header('Location'), "\n";

print "Response: ", $response->status_line, "\n";

if ($response->is_success){

print "Whee, it worked! I got that ",

$response->content_type, " document!\n";

}

elsif ($response->is_redirect) {

print "Redirect \n";

}

else {

die "Error at $url\n ", $response->status_line, "\n Aborting";

}

print "Try to get content_file...\n";

my $datafile = "OACSIM_MILCON_System_Capabilities_Mapping 20100201.xlsx";

use HTTP::Request::Common;

$response = $browser->request( GET($url), $datafile );

exit;

Thanks Kit Lueder cell 703-577-2463 clueder@aagPLEASENOSPAM.dese.com

-- KitLueder - 2010-03-23

Discussion and Answer

I have not done that myself, so I can't give you good advise. One question though that affects your scripted authentication: Is your TWiki server configured to use template login or Apache login? Check the {LoginManager} setting in configure.

-- PeterThoeny - 2010-03-23

I can't find that LoginManager setting.

-- KitLueder - 2010-03-24

"I have not done that myself, so I can't give you good advise." OK, do you have ANY example of calling the scripts from any application? Thanks, Kit.

-- KitLueder - 2010-03-24

On login, if you are using template login you get a login screen as part of the page (like here on twiki.org), if you use Apache login you get a small dialog box to login.

-- PeterThoeny - 2010-03-24

OK thanks, I get the template login twikiscreen, not a separate dialog-box small-window.

-- KitLueder - 2010-03-24

Actually in the second code example, I think the login is succeeding in my first connection attempt (where the user/pw are in the URL). But I don't succeed in downloading the resulting file.

use LWP::UserAgent;

my $url2 = 'https://k2d.aag.dese.com/twiki/bin/viewfile/Main/OACSIM_MILCON/W91quz07D0004F708?filename=OACSIM_MILCON_System_Capabilities_Mapping.xlsx;rev=5;username=KitLueder;password=xxxx';

use LWP 5.66; my $browser = LWP::UserAgent->new;

my $response = $browser->get($url2);

my $responseCode2 = $response->code; print "RespCode 1stGet:", $responseCode2, "\n";

use HTTP::Request::Common; $response = $browser->request( GET($url2), $datafile ); exit;

This doesn't result in download either (instead of the two lines above before the exit command:

print "Try to get content_file...\n"; use HTTP::Request::Common; $response = $browser->get($url2, ':content_file' => $datafile, );

Any ideas of how to get the file to download? Thanks Kit.

-- KitLueder - 2010-03-29

Closing this question after more than 30 days of inactivity. Feel free to reopen if needed. Consider engaging one of the TWiki consultants if you need timely help. We invite you to get involved with the community, it is more likely you get community support if you support the open source project!

-- PeterThoeny - 2010-05-02

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Unanswered
Title Perl code to call TWiki URL, HTTPS/SSL, with authentication
SupportCategory CategoryAuthentication
TWiki version 4.3.0
Server OS Windows Server 2003 R2
Web server Apache 2.2.9
Perl version 5.10.0
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2010-05-02 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.