Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^5: Windows single sign-on / NTLM question

by haukex (Bishop)
on Jan 23, 2019 at 19:48 UTC ( #1228886=note: print w/replies, xml ) Need Help??

in reply to Re^4: Windows single sign-on / NTLM question
in thread Windows single sign-on / NTLM question

Thanks for the update! Sometimes calling the native tools turns out to be the "easiest" way to go, in cases like that I usually make sure the interface is as clean as possible.

I've not actually integrated into my scripts, but as a proof of concept, it works.

A quick test shows me that something like this seems to work:

use IPC::Run3 'run3'; run3 ['powershell', '-Command', 'Invoke-WebRequest', '-Uri', $uri, '-OutFile', $filename, '-UseDefaultCredentials']; $? and die "run3 failed with \$?=$?";

(I'm using IPC::Run3 because newer versions use Win32::ShellQuote under the hood, and it allows redirection of STDIN/OUT/ERR if desired. For really complicated cases, I guess PowerShell's -EncodedCommand is probably the way to go.)

Update: Wrapped up in a function:

use File::Temp qw/tempfile/; use IPC::Run3 'run3'; sub invoke_webrequest { my $uri = shift; my ($tfh,$tfn) = tempfile(UNLINK=>1); close $tfh; run3 ['powershell', '-Command', 'Invoke-WebRequest', '-Uri', $uri, '-OutFile', $tfn, '-UseDefaultCredentials']; $? and die "run3 failed with \$?=$?"; open my $fh, '<', $tfn or die "$tfn: $!"; my $data = do { local $/; <$fh> }; close $fh; unlink $tfn; return $data; }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1228886]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-01-18 23:23 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (54 votes). Check out past polls.