Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by markong (Pilgrim)
on Jan 03, 2019 at 00:25 UTC ( [id://1227943]=note: print w/replies, xml ) Need Help??


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

The even clunkier solution was to throw the URL at chrome via a system call and then look for the file in the end user's download directory.

There are some modules to easily drive Firefox/Chrome on CPAN: chrome, chromium ...

  • Comment on Re^3: Windows single sign-on / NTLM question

Replies are listed 'Best First'.
Re^4: Windows single sign-on / NTLM question
by DamnitAddie (Novice) on Jan 23, 2019 at 11:39 UTC

    As a follow-up, in case any other sad sad person wants to do something silly like me.... It appears that the least clunky, but still not 100% Perl solution is to use PowerShell to grab the file. This works for my situation because most of the desktops have PowerShell installed as part of my company's default image and for those who don't, it's approved software on our internal Software Center. In any event, the relevant PS code snip is:

    Invoke-WebRequest -Uri $REMOTE -OutFile $LOCAL -UseDefaultCredentials

    Specifically, that "UseDefaultCredentials" will tell PS to throw your windows login info to the server. I've not actually integrated into my scripts, but as a proof of concept, it works.

      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (8)
As of 2024-04-16 18:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found