Reason

I am trying to change JIRA::Client::Automated to use cookie authentication instead of basic_auth(user/password). It is requested by admins as basic authentication is overloading AD.

I should add that code is fully functional when running with basic authentication. The main change is in "new" method. Here I add a line with cookie jar & removed basic authentications.

sub new_c { my ($class, $url, $cookie) = @_; my $self = { url => $url, auth_url => $auth_url }; bless $self, $class; $self->{_ua} = LWP::UserAgent->new(); $self->{_ua}->cookie_jar({cookies => $cookie} ); return $self; }
Cookie to the code is supplied in the form of text: JSESSIONID=F97AC6F5AD33D54D0C06F4CBF0230C43 in JSON cookie jar is visible:
$VAR1 = bless( { '_ua' => bless( { 'cookie_jar' => 'JSESSIONID=F97AC6F +5AD33D54D0C06F4CBF0230C43', }, 'LWP::UserAgent' ), }
Then I post GET request and answer is 401 error.
garbage after JSON object, at character offset 4 (before "Can't locate + object .. .") at C:/strawberry/perl/site/lib//JIRA/Client/Automated.pm line 385. request GET /rest/api/latest/issue/JIML-3044: at main.pl line 30 response 401 Unauthorized: {"errorMessages":["You do not have the perm +ission to see the specified issue.","Login Required"],"errors":{}} at main.pl li +ne 30 Unable to GET /rest/api/latest/issue/JIML-3044: 401 Unauthorized{ errorMessages => [ "You do not have the permission to see the specified issue.", "Login Required", ], errors => {}, }
I suspect I messed correct cookie jar writing, but out of ideas how to write it.

Note, I have access rights for the issue, the cookie itself is functional - both checked using curl. Any idea to supply cookie to cookie_jar to be usable?

There is very similar question in monastery: http://www.perlmonks.org/?node_id=456612, but it was not answered in a way I can use.

In reply to what is the correct way to set cookie in LWP::UserAgent by Eroln

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.