Access JIRA API with api key without username and password

后端 未结 3 1494
不知归路
不知归路 2021-01-21 20:21

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 has

相关标签:
3条回答
  • 2021-01-21 20:28

    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'
      }
    )
    
    0 讨论(0)
  • 2021-01-21 20:43

    Best approach for this is to read the documentation of the JIRA version you are using, since different versions could have different ways to approach Rest APIs.

    For me below endpoint worked with Basic auth:

    curl -u username:password -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/createmeta
    
    0 讨论(0)
  • 2021-01-21 20:47

    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.

    0 讨论(0)
提交回复
热议问题