Access JIRA API with api key without username and password

青春壹個敷衍的年華 提交于 2019-12-20 03:44:14

问题


Currently I'm accessing JIRA API in C#.Net application with username and password. But I need to access the JIRA API without entering a username and a password even without hashed username and passwords. Is there any way to create an API key and access JIRA API with that?


回答1:


Yes, JIRA supports OAuth for that purpose, see: https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+OAuth+authentication

Unfortunately there's no C# sample code provided, but you should be able to assemble a solution from the other programming languages here: https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples/src

You should use a generic OAuth library anyhow.




回答2:


Oauth is great for when you need the actual user to log in and you are in the context of a browser.

However, for server-to-server communication that is not linked to any specific user (e.g. CI) you may want to create a "bot" account on your jira server and authenticate with API tokens. Creation of tokens is described here: https://confluence.atlassian.com/cloud/api-tokens-938839638.html

Then you can use [user-email]:[auth-token] as user/password to basic auth. Examples:

Curl

curl -u bot@company.com:AAABBBCCC https://[company].atlassian.net/rest/api/latest/issue/DEV-123

NodeJS got:

const issueContent = await gotService.get(
  'https://[company].atlassian.net/rest/api/latest/issue/DEV-123',
  {
    auth: 'bot@company.com:AAABBBCCC'
  }
)


来源:https://stackoverflow.com/questions/28193366/access-jira-api-with-api-key-without-username-and-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!