Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Authorizing with NTLM - Problem Domain

by Feneden (Acolyte)
on May 18, 2018 at 05:49 UTC ( [id://1214813]=perlquestion: print w/replies, xml ) Need Help??

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

Hi there,

I asked a rather similar question some time ago. On the former post I found a solution. Now I want to use a different user. The problem is: -> The user is from a different domain: itīs not like MyCompanyNameDE\username instead itīs like MyCompanyNameCOM\username.

When I use a username which is on the MyCompanyNameDE domain, I just can insert the raw username into the "user" field.

Here is the code I am using to play the challenge-response game with the server:

my $Options = { user => 'UsernameIsHere', password => "***********", domain => 'ServerAddressIsHere.com/', timeout => 30, protocol => "https", AuthMethod => "NTLM", ##BrowserAgent => "MSIE 6.0; Windows NT 5.0", RequestMethod => "GET", ##DataDir => "/tmp", }; ##my $log = "/var/tmp/get_url.log"; ##my $DataDir = "/tmp"; my $ua = LWP::UserAgent->new(keep_alive=>'1'); ##agent=>'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)', ###################################### # First stage of NTLM authentication # ###################################### my $url = "http://ServerAddressIsHere.com/mbSDKService/MsgSDK.asmx/Run +Query?queryName=QueryNameIsHere"; ntlm_domain($Options->{'domain'}); ntlm_user($Options->{'user'}); ntlm_password($Options->{'password'}); my $Authorization = Authen::NTLM::ntlm(); my $header = HTTP::Headers->new( ##Content_Type => 'text/html', ##'WWW-Authenticate' => $Options->{'AuthMethod'} ); $header->header('Authorization' => "NTLM $Authorization"); my $request = HTTP::Request->new($Options->{'RequestMethod'} => $url, +$header); my $res = $ua->request( $request ); ################################## # Second stage of authentication # ################################### ### challenge my $Challenge = $res->header('WWW-Authenticate'); $Challenge =~ s/^NTLM //g; $Authorization = Authen::NTLM::ntlm($Challenge); $header->header('Authorization' => "NTLM $Authorization"); $request = HTTP::Request->new($Options->{'RequestMethod'} => $url, $he +ader); $res = $ua->request( $request ); ### ntlm reset for eventual connects with a different user #ntlm_reset(); if($res->is_success) { $data = $res->decoded_content(); } else { print "ERROR: Can not dump data from $url\nReturned code: " . $res +->code . " (" . $res->status_line . ")\n"; exit; }

All in all this request is about obtaining an XML from a web service.

Thanks in advance! Regards Feneden

Replies are listed 'Best First'.
Re: Authorizing with NTLM - Problem Domain
by soonix (Canon) on May 19, 2018 at 12:01 UTC
    Late to the party, and haven't used NTLM with HTTP, but:

    you have the same ServerAddressIsHere.com in your option as in the URL, therefore it is not clear to me wether you tried the obvious

    domain => 'MyCompanyNameCOM', user => 'username', password => "***********",
Re: Authorizing with NTLM - Problem Domain
by Anonymous Monk on May 18, 2018 at 06:41 UTC

      Hey

      not really... I mean, I alreday tried it like this:

      $ua->credentials($Options->{'domain'}, '', $Options->{'user'}, $Options->{'password'});

      and this:

      ntlm_domain($Options->{'domain'}); ntlm_user($Options->{'user'}); ntlm_password($Options->{'password'}); my $Authorization = Authen::NTLM::ntlm();

        I don't know anything about Authen::NTLM, and the docs aren't really helpful here, but the thread linked to in the AM post shows the method being used as $ua->credentials('10.1.1.1:80', '', 'myDomain\\user', 'password');. What is your $Options->{'user'}, have you tried my $Options = { user => 'Domain\\UsernameIsHere', ...?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1214813]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found