i want to cookie base authentication through script post function to call the rest api.
Hello,
Kindly read the following article
https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-cookie-based-authentication
Thanks Alexey, but this article is not opening as it says that we are unable to find the page you are looking for.
try this one
https://developer.atlassian.com/jiradev/jira-apis/about-the-jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-cookie-based-authentication
In short you would need to do the following:
1. Connect to Jira and get the cookie:
curl -X POST \ http://jira.example.com:8090/jira/rest/auth/1/session \ -H 'content-type: application/json' \ -d '{ "username": "myuser", "password": "mypassword" }'
It will return it the code like this
{ "loginInfo" : { "lastFailedLoginTime" : "2013-11-27T09:43:28.839+0000", "previousLoginTime" : "2013-12-04T07:54:59.824+0000", "loginCount" : 2, "failedLoginCount" : 1 }, "session" : { "name" : "JSESSIONID", "value" : "6E3487971234567896704A9EB4AE501F" } }
2. Use the cookie in the next REST API calls:
Take the value for JSESSIONID and add it to the next REST API call. For example like this
var Client = require('node-rest-client').Client; client = new Client(); // Provide user credentials, which will be used to log in to JIRA. var loginArgs = { data: { "username": "admin", "password": "admin" }, headers: { "Content-Type": "application/json" } }; client.post("http://localhost:8090/jira/rest/auth/1/session", loginArgs, function(data, response){ if (response.statusCode == 200) { console.log('succesfully logged in, session:', data.session); var session = data.session; // Get the session information and store it in a cookie in the header var searchArgs = { headers: { // Set the cookie from the session information cookie: session.name + '=' + session.value, "Content-Type": "application/json" }, data: { // Provide additional data for the JIRA search. You can modify the JQL to search for whatever you want. jql: "type=Bug AND status=Closed" } }; // Make the request return the search results, passing the header information including the cookie. client.post("http://localhost:8090/jira/rest/api/2/search", searchArgs, function(searchResult, response) { console.log('status code:', response.statusCode); console.log('search result:', searchResult); }); } else { throw "Login failed "; } });
That was code for Node.js. In post function you have to change it. If you have any futher question , then ask
@Alexey Matveev
i do not have the password of the user, if i would have it , i would have gone for the basic authentication, but to overcome this i want to get the cookie(JSESSIONID) so by passing it i could perform the cookie base authentication.
this has become the obstacle for me as i want to create the page in confluence on the script post function and to do this i have to perform the cookie base or oauth authentication but im unable to proceed with this. hoping to see a resolution from you on this problem.
Thanking in anticipation.
Regards
Aetisam
It looks like you're new here. Sign in or register to get started.