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

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

问题描述

我要创建一个JavaScript应用程序的智能电视上显示的电视仪表​​盘。
我得到的JIRA REST API仪表板的名单。我使用这个网址是:

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=

由于 os_username os_password ,JIRA知道我身份验证,并得到正确的名单。这个名单是一个我从一开始就需要,而是因为我带参数调用上面的网址 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

但上启动电视/我第一次拿到仪表板与JIRA名单有没有人验证所以它需要一个随机的列表,而不是一个我需要得到。

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.

有某种方式在JIRA与下面的命令来验证:

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

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

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

因此​​,谁能告诉我怎样可以在JIRA基本身份验证和它必须JAVASCRIPT非常重要的验证。

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

推荐答案

您从<一个得到这个href=\"https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Basic+Authentication\">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.

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

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