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

Loading browser cookies into WWW::Mechanize

by bakiperl (Beadle)
on Jul 16, 2021 at 15:58 UTC ( [id://11135069]=perlquestion: print w/replies, xml ) Need Help??

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

Folks,
I need help with WWW::Mechanize to automate a login to a page that uses Duo-Authentication. I am able to load the credentials and login but I need to silently pass the second check using the information that is saved in the cookies by the browser (Chrome or any other browser if necessary). Once this is achieved I should be able to things I was able to do before the implementation of the Duo-Authentication.

This call
$cookie_jar->load($cookie_file);
returns this warning: "Decrypted cookies is not set up at..."
Here is what I have so far.
#!/usr/bin/perl -w use strict; use Data::Dumper; use WWW::Mechanize; use HTTP::Cookies::Chrome; my $username = '**********'; my $passwd = '*********'; my $cookie_file = 'C:/Users/username/AppData/Local/Google/Chrome/User +Data/Default/Cookies'; #chrome cookies path on windows my $cookie_jar = HTTP::Cookies::Chrome->new( # chrome_safe_storage_password => '***", # I don't know what t +o do here file => $cookie_file, # autosave => 1, # ignore_discard => 0, ); $cookie_jar->load($cookie_file); my $mech = WWW::Mechanize->new( cookie_jar => $cookie_jar, ); #$mech->cookie_jar->scan(sub { print Dumper \@_ }); #print $cookie_jar->as_string; my $uri = URI->new( "https://www.*****.com" ); $mech->get( $uri ); unless ($mech->success) { my $mesg = $mech->response->status_line; print $mesg; goto END; } $mech->set_fields( username => $username, password => $passwd, ); $mech -> submit(); sleep(2); $mech->success() or die "Can't fetch the Requested page"; my @form = ( "formname" ); $mech->form_with_fields( @form ); my $value ='******'; eval {$mech->select('fieldName', $value)}; if ($@ and $@ =~ /Illegal value/) { print "This page has not been loaded..."; goto END; } END :

Replies are listed 'Best First'.
Re: Loading browser cookies into WWW::Mechanize
by Aldebaran (Curate) on Jul 17, 2021 at 01:51 UTC
    I need help with WWW::Mechanize to automate a login to a page that uses Duo-Authentication. I am able to load the credentials and login but I need to silently pass the second check using the information that is saved in the cookies by the browser (Chrome or any other browser if necessary). Once this is achieved I should be able to things I was able to do before the implementation of the Duo-Authentication.

    What does this sound like to me? Duo-Authentication is a new thing connoting dual-authentication, which can be achieved in a variety of ways. I identify Duo with the google toolchain, and it's just like them to lay claim to a semi-word.

    Meanwhile, WWW::Mechanize is not new. It is not trimmed out for what the internet has become. What's more, your objective seems to be to bypass this authentication with cookies. Preventing you from what you're attempting is the raison d'etre for duo-authentication.

    I don't know what all goes into a cookie, but it's not the data you need for the *next* duo-verification. You could put a lot of cases to rest by posting the URL you are trying to outwit.

      Aldebara,
      Actually, I have been able to achieve this Duo-authentication login easily with WWW::Mechanize::Chrome, but I could not get WMC to download hyperlinked files (pdf, csv and images) without getting them corrupted and wrapped into html tags.
      This simple download has been automatic with WWW::Mechanize. That's the reason why I want to see if WM can do the same thing as WMC by using the cookies.
Re: Loading browser cookies into WWW::Mechanize
by Anonymous Monk on Jul 17, 2021 at 05:39 UTC

    chrome_safe_storage_password => '***", # I don't know what t +o do here

    follow the documentation? The part that says how to retrieve password?

      Unfortunately there is no documentation about how to do it on windows systems.

        "I don't know how to do this on Windows. If you know, send a pull request. That goes for other systems too."

        See Windows Credential Manager, IIRC cmdkey is the command line tool, and there's an API.

Log In?
Username:
Password:

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

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

    No recent polls found