【发布时间】:2015-03-27 10:02:54
【问题描述】:
目前我正在使用用户名和密码在 C#.Net 应用程序中访问 JIRA API。但是即使没有散列的用户名和密码,我也需要在不输入用户名和密码的情况下访问 JIRA API。有什么方法可以创建 API 密钥并使用它访问 JIRA API?
【问题讨论】:
标签: authentication jira jira-rest-api
目前我正在使用用户名和密码在 C#.Net 应用程序中访问 JIRA API。但是即使没有散列的用户名和密码,我也需要在不输入用户名和密码的情况下访问 JIRA API。有什么方法可以创建 API 密钥并使用它访问 JIRA API?
【问题讨论】:
标签: authentication jira jira-rest-api
是的,JIRA 为此支持 OAuth,请参阅:https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+OAuth+authentication
很遗憾,没有提供 C# 示例代码,但您应该能够在此处从其他编程语言组装解决方案: https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples/src
无论如何,您都应该使用通用 OAuth 库。
【讨论】:
当您需要实际用户登录并且您处于浏览器的上下文中时,Oauth 非常适合。
但是,对于未链接到任何特定用户(例如 CI)的服务器到服务器通信,您可能需要在您的 jira 服务器上创建一个“机器人”帐户并使用 API 令牌进行身份验证。此处描述了令牌的创建:https://confluence.atlassian.com/cloud/api-tokens-938839638.html
然后您可以使用 [user-email]:[auth-token] 作为基本身份验证的用户/密码。例子:
卷曲
curl -u bot@company.com:AAABBBCCC https://[company].atlassian.net/rest/api/latest/issue/DEV-123
NodeJS 得到:
const issueContent = await gotService.get(
'https://[company].atlassian.net/rest/api/latest/issue/DEV-123',
{
auth: 'bot@company.com:AAABBBCCC'
}
)
【讨论】:
最好的方法是阅读您正在使用的 JIRA 版本的文档,因为不同的版本可能有不同的方法来处理 Rest API。
对我来说,以下端点使用基本身份验证:
curl -u username:password -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/createmeta
【讨论】: