如何在JavaScript中使用JIRA REST API的基本身份验证? [英] How to use Basic Authentication with JIRA REST API in JavaScript?

查看:972
本文介绍了如何在JavaScript中使用JIRA REST API的基本身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为智能电视创建一个JavaScript应用程序,以在电视上显示仪表板。
我得到了JIRA REST API的仪表板列表。我使用的网址是:

  jira / rest / api / 2 / dashboard?startAt =& maxResults = 

然后我创建一个墙板,如下所示在电视上显示:

  jira / plugins / servlet / Wallboard /?dashboardId =& os_username =& os_password = 
os_username 和 os_password ,JIRA知道i'p>

< m验证并获得正确的列表。这个列表是我需要从一开始,但因为我调用上面的参数 os_username os_password it确实得到了正确的列表



但是在电视启动时,我第一次得到仪表板列表与JIRA没有一个认证,所以它需要一个随机列表,而不是我需要得到的。



有一些方法使用以下命令在JIRA中进行身份验证:

  curl -D- -u fred:fred -X GET -HContent-Type:application / jsonhttp://example.com/rest/api/2/issue/ createmeta 

但我不知道如何在JavaScript中使用该命令。



任何人都可以告诉我如何在JIRA中通过基本身份验证进行身份验证,并且非常重要的IT部门必须是JAVASCRIPT。

解决方案

您从此处,我猜。在同一页上,它解释了如何自己做。我将翻译您需要做的步骤,以便管理在JS中执行相同的请求。


  1. 请求方法应该 GET

  2. 您应该有两个标题:授权标题和内容类型标题
    您的Content-type标题应如下所示:
    Content-Type:application / json


b $ b

对于授权头:


  1. 创建一个字符串形式 username:password / li>
  2. Base64 对字符串进行编码(使用 window.btoa() window.atob()) - 你实际上不需要第二个,但我把它放在那里供参考

  3. 提供内容为Basic的授权标头,后跟编码字符串。例如,字符串fred:fred在base64中编码为ZnJlZDpmcmVk,因此您的授权头应该像:
    授权:Basic ZnJlZDpmcmVk

因此,最后,您需要使用提供的两个标题来发出GET请求,并且您应该是授权的。 BEWARE Base64是可逆的并不是一个加密函数,它是编码,请求将通过HTTPS当然,但是Base64编码的字符串可以颠倒,如果SSL破裂。


I'm creating a JavaScript app for a Smart TV to show dashboards on the tv. I get the list of dashboards with the JIRA REST API. The url I use for this is:

jira/rest/api/2/dashboard?startAt=&maxResults=

afterwards I create a wallboard as followed to show them on the tv:

jira/plugins/servlet/Wallboard/?dashboardId=&os_username=&os_password=

because of the os_username and os_password, JIRA knows i'm authenticated and gets the right list. this list is the one i need from the beginning but because i call the url above with the parameters os_username and os_password it does get the right list

but on start up of the tv/the first time i get the list of dashboards with JIRA there is no one authenticated so it takes a random list, not the one i need to get.

there is some way to authenticate in JIRA with the command below:

curl -D- -u fred:fred -X GET -H "Content-Type: application/json"         http://example.com/rest/api/2/issue/createmeta

but i don't know how to use that command in JavaScript.

So can anyone tell me how i can authenticate in JIRA with basic authentication and very important IT HAS TO BE JAVASCRIPT.

解决方案

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. 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"

For the Authorization header:

  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"

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.

这篇关于如何在JavaScript中使用JIRA REST API的基本身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆