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

Hello, anyone has idea of how to build a proxy which does external user ---http/basic auth-->app/proxy--http/NTLM-->internal web server ? something as (LWP::Authen::NTLM which unluckily is not out yet) any hack with Authen::NTLM and LWP? thanks G.

Replies are listed 'Best First'.
Re: NTLM http authen - basic authen
by marcus (Scribe) on Dec 17, 2001 at 23:32 UTC
    Hi.

    IMHO this isn't a perl issue, and might be hard to do, as ntlm isn't really well documented by Microsoft. However, look at this url for a little more information about ntlm proxy auth.

    qw(marcus)

Re: NTLM http authen - basic authen
by Dr. Who (Initiate) on Mar 20, 2002 at 16:07 UTC
    I recently had the same problem and solved it with code very similar to what I've pasted below.
    Best of luck
    ------------------------------------------
    #! c:\perl\bin\perl.exe $| = 1; use LWP::Simple; use HTTP::Request; use HTTP::Request::Common; use HTTP::Response; use LWP::UserAgent; use Authen::NTLM; use CGI::Carp qw(fatalsToBrowser); use Net::HTTP; use HTTP::Headers; use Mail::Sendmail; print "Content-type: text/html\n\n"; #_____________________________________________________________________ +__________ sub Giddyup ($){ my($content) = @_; ntlm_reset(); ntlm_domain(''); ntlm_user(YOURUSERNAME); ntlm_password(YOURPASSWD); my $Type1MSG = ntlm(''); #__________First connection attempt_________ #make a user agent my $ua = LWP::UserAgent->new( keep_alive => 1, timeout => 30, ); #make a header header object my $header1 = HTTP::Headers->new; $header1->authorization('NTLM '. $Type1MSG); $header1->content_type('application/x-www-form-urlencoded'); #Make a request and response object my $req1 = HTTP::Request->new(POST => 'http://www.yoursite.whatev +er', $header1, $content); my $resp1 = $ua->request($req1); my $code1 = $resp1 -> code; my $Type2MSG = $resp1 -> www_authenticate; $Type2MSG =~ s/NTLM //; #__________Second connection attempt_________ my $Type3MSG = ntlm($Type2MSG); #make a header header object my $header2 = HTTP::Headers->new; $header2->authorization('NTLM '. $Type3MSG); $header2->content_type('application/x-www-form-urlencoded'); #Make a request and response object my $req2 = HTTP::Request->new(POST => 'http://www.yoursite.whatev +er', $header2, $content); my $resp2 = $ua->request($req2); $code2 = $resp2 -> code; if ($code2 == 200){ print "<p>NTLM Connection established (Code:$code2)... req +uest sent</p>"; } } #_____________________________________________________________________ +__________ #CODE STARTS HERE print "<html><head><title>Enter Title Here</title></head><body>"; my $content = 'Field1=' . $Field1 . 'Field2=' . $Field2 . 'Field3=' . +$Field3 . 'Field4=' . $Field4 . 'Field5=' . $Field5; print "The content string contains:\n $content\n"; Giddyup($content);
Re: NTLM http authen - basic authen
by em (Scribe) on Dec 19, 2001 at 04:13 UTC