If you don't want to encode your credentials in every request here is how to do it using cookies.
When requesting the cookie you don't need to add any authorization on the headers. This method will accept a JSON string with the user name and password and the URL. It will return the cookie values.
public async Task<JiraCookie> GetCookieAsync(string myJsonUserNamePassword, string JiraCookieEndpointUrl) { using (var client = new HttpClient()) { var response = await client.PostAsync( JiraCookieEndpointUrl, new StringContent(myJsonUserNamePassword, Encoding.UTF8, "application/json")); var json = response.Content.ReadAsStringAsync().Result; var jiraCookie= JsonConvert.DeserializeObject<JiraCookie>(json); return jArr; } } public class JiraCookie { public Session session { get; set; } } public class Session { public string name { get; set; } public string value { get; set; } }
When I call it using url: http://[baseJiraUrl]/rest/auth/1/session it returns the following JSON response:
{ "session" : -{ "name" : JSESSIONID, "value" : cookieValue }
Keep in mind the URL above is valid in the version of JIRA I'm using and may vary depending on which version you're using. Read the JIRA API documentation for the correct URL for the version you are using. I'm using the following: https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#auth/1/session
Remember you'll have to store your cookie and use it on every subsequent request. Check out this answer on how add cookies to your HttpClient request: How do I set a cookie on HttpClient's HttpRequestMessage.
Once you're done with the cookie (logging out) simply send a delete http request with the same URL as the post.