http代理服务器(十三)jira bitbucket confluence

https://blog.51cto.com/u_15228964/2820139

首先:这是jira api地址: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-field-fieldKey-option-get 

这个文档中 Authentication and authorization章节介绍的获取Authentication 都比较麻烦。

   其次:通过搜索我发现另外一个Api介绍文档 https://developer.atlassian.com/server/jira/platform/basic-authentication/ 

该文档中Security章节中介绍了几种访问api的方式,我使用了Basic Authentication,这种方式相对来说最简单、最容易理解,因为它使用的是自己登录Jira的用户名和密码。下面就说明如何使用

   方法一:

      英文原文如下:

     Most client software for sending requests automatically generate the authorization header when you provide a username and password.

For example, in cURL you can specify a username and password combination with the -u argument to send a request to a Jira site

      意思就是说如果我们提供用户名和密码,大多数用于发送请求的客户端软件会自动生成授权标头    

      比如:curl -u username:password -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/createmeta  即可调通api了。

       这种方式需要明文提供自己的用户名和密码,相对风险比较高。况且如果我们想使用httpClient调用,这种方式,也不满足要求

   方法二:

      英文原文如下:

Build a string of the form username:password.
Encode the string to Base64.
Supply an authorization header with format Authorization: Basic {encoded-string}. Make sure to replace {encoded-string} with your encoded string from Step 2 
     意思就是通过Base64加密的方式加密username:password,然后在http请求的header中添加Basic {encoded-string}即可

    比如:curl -H "Authorization: Basic {encoded-string}" -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/createmeta 即可调通api了

  第三:编写自己调用httpClient的工具,在header中设置Authorization: Basic {encoded-string}即可,就可以随意调用Jira api。

 

同样能用于bitbucket

String id = "xx";
String pw = "xx";
String token = Base64.getEncoder().encodeToString((soeid + ":" + pw).getBytes());
token = "Authorization::Basic " + token;
// http://localhost:8995/jira/secure/RapidBoard.jspa...
new Thread(new HttpServerJob(8995, "https://jira.host.com", "443", token)
.setCrc(false)
).start();

// http://localhost:8996/bitbucket/projects/...
new Thread(new HttpServerJob(8996, "https://bitbucket.host.com", "443", token)
.setCrc(false)
).start();

 

posted on 2023-04-18 13:57  silyvin  阅读(46)  评论(0)    收藏  举报