How do I handle login authentication using Atlassian.SDK

I'm writing my own Visual Studio startpage for personal use, and want to embed my open Jira tickets there using the Atlassian SDK nuget package. However, I'm setting it up as a more generalized project, so I can share it with interested colleagues. This means that the username and password used to connect are given by the user on first use and may not be correct. On incorrect logins, I want to give the user the ability to change the given username or password, but to do this I need to know that that was the actual problem in the first place.

Tests show me that giving an incorrect username or password throws an Exception with message "The request was aborted: The connection was closed unexpectedly.". How can I check if this was a problem with authentication or some other issue?

I've noticed that, when there's no internet connection available, the exception's message is "The remote name could not be resolved: 'mycompany.atlassian.net'". So I could filter those out to be a bit more sure, but this doesn't look like a good solution to me.

I'm using this code to fetch my issues:

var jira = Jira.CreateRestClient("https://mycompany.atlassian.net", $"{_username}@mycompany.com", _password);
var issuesForUser = jira.Issues.Queryable.Where(issue => issue.Assignee == _username).ToList();

Any help is greatly appreciated.

1 answer

0 vote
Alexey Matveev Community Champion Dec 02, 2017

Hello,

I am not sure about the library which you are using but maybe you could make a call to auth/1/session. I think you can get a more meaningful exception from this REST API call. You can read more about auth/1/session here:

https://docs.atlassian.com/jira/REST/cloud/#auth/1/session

Thanks for the fast response! I (wrongly) assumed that the nuget package was an official Atlassian one. After checking out the source, I can see that it actually uses the .NET rest client to make normal rest calls (and does so poorly). The link you've provided is a lot more useful. Thanks again.

namilkim I'm New Here Feb 07, 2018

Hi,  

I am call http://myserver.co.kr/rest/auth/1/session

but server only return 404 not found error

 

hot to fix it?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

239 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you