JIRA REST API calls fail when using JSESSIONID cookie authentication using urlfetch

Jonathon Broughton February 25, 2016

I have a Google App Engine Python application that interacts with a JIRA Cloud instance.

To date the application makes urlfetch calls to JIRA using Basic Authentication but as it is now making dozens of separate REST calls both POST and GET I was hoping that using cookie authentication would reduce the latency somewhat.

example Basic-Authentication code that works:

result = urlfetch.fetch(jira_url,
                        deadline=60,
                        headers={"Authorization": 
                        "Basic %s" %
				            base64.b64encode("%s:%s" % (username,
                                                        password))
                        })

and cookie alternative:

result = urlfetch.fetch(jira_url,
                        deadline=60,
                        headers={"X-Atlassian-Token": "no-check",
                                 "Cookie": "JSESSIONID=529…snip…C4C"
                        })

I retrieved the JSESSIONID successfully using the instructions but the cookie query will only return "401 - Unauthorized" error while loading this page. errors as if the cookie has expired.

{ "errorMessages" : 
  [ "You do not have the permission to see the specified issue.",
    "Login Required" ],
  "errors" : {}
}

In case it is relevant, I am recalling the cookie from Memcache as most of the interactions are made from a Task Queue and necessarily a separate thread, but the cookie is generated immediately before the recall.

2 answers

0 votes
Eric Molitor October 20, 2016

Hi Jeff,

The node.js example you linked to actually fails due to the same issue when using the cloud instance. Authentication works but the embedded query in the example the attempts to run with the cookie fails with a 401. Would be good to have someone at Atlassian either confirm the issue or provide some guidance.

Looking at the actual responses coming from the Atlassian on demand servers the cookie expiration is january 1st 1970. Not sure if thats the root cause but would make sense the next request would return a 401.

0 votes
Jeff
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 7, 2016

Your request looks pretty much correct based on the documentation - https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-cookie-based-authentication.

The only thing that maybe I would recommend is setting your content-type to application/json in your headers as well, as per the urlfetch documentation if you do not specify, then it will default to www-urlform-encoded, which is likely to cause problems? From https://cloud.google.com/appengine/docs/python/outbound-requests:

When sending an HTTP POST request, if a Content-Type header is not set explicitly, the header is set to x-www-form-urlencoded. This is the content type used by web forms.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events