Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Authenticate via REST::Client against Rundeck API

by hdb (Monsignor)
on Mar 14, 2019 at 13:48 UTC ( #1231256=note: print w/replies, xml ) Need Help??


in reply to Re^2: Authenticate via REST::Client against Rundeck API
in thread Authenticate via REST::Client against Rundeck API

Sorry if it did not work. I have no access to a Rundeck instance so I cannot test. Just for my personal education: did you try my proposed code or did you conclude from the $res that I won't work?

Replies are listed 'Best First'.
Re^4: Authenticate via REST::Client against Rundeck API
by XavierFR (Novice) on Mar 14, 2019 at 15:31 UTC
    Hi, hdb,

    I tried your code, too. It actually looks like that :

    my $ua = LWP::UserAgent->new( 'agent' => basename($0), 'timeout' => $TIMEOUT, ); my $cookie_jar = HTTP::Cookies->new( file => "perlcookie.txt", autosave => 1, ignore_discard => 1, ); $ua->cookie_jar( $cookie_jar ); my $client = REST::Client->new( { host => $url, timeout => 10, useragent => $ua, follow => 1, } ); $client->addHeader ("content-type", 'application/x-www-form-urlencoded +'); $res = $client->POST( "j_security_check", "j_username=$username j_password=$password", ); print Dumper ($res); $res = $client->GET("api/14/system/info"); $rc = $client->responseCode (); print Dumper ($res); exit ( $rc);

    And cookie file contains that

    #LWP-Cookies-1.0 Set-Cookie3: JSESSIONID=node0npoji3aifa9r1c2xuxr6xvppe221132.node0; pa +th="/"; domain=[SNIP]; path_spec; discard; HttpOnly; version=0

    Unlike previous attempts, all HTTP transactions look good with this version of the code

    Xavier
Re^4: Authenticate via REST::Client against Rundeck API
by XavierFR (Novice) on Mar 15, 2019 at 08:23 UTC

    SOLVED (almost) !

    By default, LWP::UserAgent forwards only GET and HEAD requests. Adding POST gives me the login page.

    Xavier

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-04-17 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?