且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在JavaScript中使用基本身份验证与JIRA REST API?

更新时间:2022-02-07 15:31:18

您从here,我presume。那么在同一页上它解释了如何做自己。我将翻译,你需要为了做的步骤来管理做在JS同样的要求。

You got this from here, I presume. Well on the same page it is explained how to "do it yourself". I will "translate" the steps that you need to do in order to manage to do the same request in JS.


  1. 请求方法应该是获取

  2. 您应该有2头:认证头和Content-Type头
    您的Content-type头应该是这样的:
    内容类型:应用程序/ JSON

  1. Request Method should be GET
  2. You should have 2 headers: Authorization Header and Content-Type Header. Your Content-type header should looks like: "Content-Type: application/json"

有关授权头:


  1. 构建格式的字符串的用户名:密码

  2. 的Base64 EN code中的字符串(使用的 window.btoa()并的 window.atob()) - 的你其实并不需要第二个,但我把它放在那里,以供参考

  3. 供应与内容基本的授权头后面是EN codeD字符串。例如,字符串弗雷德:弗雷德恩$ C以base64 $ CS为ZnJlZDpmcmVk,让你的认证头应该像:
    授权:基本ZnJlZDpmcmVk

  1. Build a string of the form username:password
  2. Base64 encode the string (Use window.btoa() and window.atob()) - You actually DO NOT need the second one but I put it there for reference
  3. Supply an "Authorization" header with content "Basic " followed by the encoded string. For example, the string "fred:fred" encodes to "ZnJlZDpmcmVk" in base64, so your Authorization Header should look like": "Authorization: Basic ZnJlZDpmcmVk"

所以,你需要提供与两个头的GET请求,您应该被授权结束。此外当心Base64是reverseable 而非加密的功能。据编码。该请求将通过当然HTTPS,但Base64编码的连接codeD字符串可以互换,如果SSL被打破了。

So in the end you need to make your GET request with the two Headers supplied and you should be Authorized. Also BEWARE Base64 is reverseable and NOT an encryption function. It is encoding. The request will go through HTTPS of course, but the Base64 encoded string could be reversed if SSL is broken.