solidify / jira-azuredevops-migrator

Tool to migrate work items from Atlassian Jira to Microsoft Azure DevOps/VSTS/TFS.
MIT License
264 stars 228 forks source link

Unauthorised access error in jira-export #3

Closed Jura closed 5 years ago

Jura commented 6 years ago

Following command jira-export -u [bitbucket username] -p [personal token] --url [url of the project] --config config.json --force producing uncaught 401 Unauthorized error after passing initial connection step. Apparently it fails at https://github.com/solidify/jira-azuredevops-migrator/blob/80bb539fa33a433d1f6a425d5ce2151306982701/src/WorkItemMigrator/JiraExport/JiraProvider.cs#L36 since here is what I got in debug log:

Jira Exporter v1.0.10
Copyright (c) Solidify
Connecting to Jira...
Connected to Jira.
Gathering project info...
Unexpected error: System.AggregateException: One or more errors occurred. ---> System.Security.Authentication.AuthenticationException: Response Content: <html>

<head>
    <title>Unauthorized (401)</title>

--- html source of the error page ---

</html>
   at Atlassian.Jira.Remote.JiraRestClient.GetValidJsonFromResponse(IRestRequest request, IRestResponse response)
   at Atlassian.Jira.Remote.JiraRestClient.<ExecuteRequestAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Atlassian.Jira.Remote.JiraRestClient.<ExecuteRequestAsync>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Atlassian.Jira.Remote.IssueFieldService.<GetCustomFieldsAsync>d__2.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at JiraExport.JiraProvider.Initialize(JiraSettings settings)
   at JiraExport.JiraCommandLine.ExecuteMigration(CommandOption user, CommandOption password, CommandOption url, CommandOption configFile, Boolean forceFresh)

Just to be clear - I don't have admin rights for the Jira project, just normal project member access level

MOlausson commented 6 years ago

Thanks for reporting, we'll have a look. What version of Jira are you on? Also it would be helpful if you could share the format of the url you are using.

Jura commented 6 years ago

It;'s Jira cloud (latest version, I presume: Jira c7720088 in Help -> ABout Jira menu).

I tried URL in the format of https://[org_name].atlassian.net and https://[org_name].atlassian.net/projects/[project_name] - both end up with the same error

MOlausson commented 6 years ago

I've tried to repo but it works with a normal user in my account. Is it possible for you to test with a different account or give a bit more context on your permission setup?

Jura commented 6 years ago

I assigned account to the project admin role and also listed it as project lead in Jira cloud

image

but result is exactly the same. I'm also attaching log for your reference

log.6753f8b4-aa6e-4c68-ac5a-5d6a88ca6bbe.txt

Jura commented 5 years ago

@MOlausson , I cannot validate this issue anymore since I lost access to Jira Cloud and Jira Server is not affected. I think this issue can be closed as non-reproducible.

vesselinmilanov commented 5 years ago

Hi, i have the same issue: error.txt

I tried with 3 accounts and tried URL in the format of https://[org_name].atlassian.net and https://[org_name].atlassian.net/projects/[project_name] - both end up with the same error

We use Jira CLOUD.

Thank you .

judecot commented 5 years ago

Just have the same problem. Solved by creating an API Token in my account settings. Then paste this token in the -p argument of the jira-export command.

Go to your Account Settings > Security > API Token to create a new one

MOlausson commented 5 years ago

@JulienDecottignies thanks for the suggestion. I'll have to check what makes username/password work on most accounts but not all. @vesselinmilanov happy to take a call and try to figure it out together since I can't repro. But using a token should get you unblocked.

vesselinmilanov commented 5 years ago

Yes - after many tries i discover this workaround with API Token.

Thank you .

MOlausson commented 5 years ago

Ok, so good for now @vesselinmilanov ?

ndbadmin commented 5 years ago

I found using the API token was necessary as well - regular password didn't work. Got the token from here: https://id.atlassian.com/manage/api-tokens.

MOlausson commented 5 years ago

Ok, sorry to hear but good you got it resolved @ndbadmin. Did you try using your Jira username as well? The api auth seems to behave differently when using username, email or tokens.

Here's an example (exported from the Users admin in Jira);

username,full_name,email,active,created,Last   active in Confluence,Last active in Stride,Last active in Jira,Last active in   Opsgenie,Last active in Statuspage
--
admin,Mathias   Olausson,mathias.olausson@solidify.se,Yes,5 Feb 2018,Never logged in,Never   logged in,2 May 2019,Never logged in,Never logged in
BenOberholzer commented 5 years ago

Thank you for this thread! I've been searching for this question and the token did the trick!