简体   繁体   English

JIRA Cloud REST API:禁止 (403) 错误

[英]JIRA Cloud REST API : Forbidden (403) error

I'm trying to utilise the JIRA Cloud REST API in an application I'm developing.我正在尝试在我正在开发的应用程序中使用 JIRA Cloud REST API。 Recently I've started getting 403 errors.最近我开始收到 403 错误。 My integration was reliable up until about a week ago, however these error responses have started to become very frequent.直到大约一周前,我的集成都是可靠的,但是这些错误响应开始变得非常频繁。

I've followed the documentation for 3LO code grants .我遵循了3LO code grants的文档。 Currently, I have:目前,我有:

  1. an application called "App" setup under the application dashboard在应用程序仪表板下设置一个名为“App”的应用程序
  2. in the application dashboard, my "App" has access to both "Jira platform REST API" and "Authorization code grants"在应用程序仪表板中,我的“应用程序”可以访问“Jira 平台 REST API”和“授权代码授权”
  3. under "Jira platform REST API" for my "App", the View Jira issue data and View user profiles options are both added/enabled在我的“应用程序”的“Jira 平台 REST API”下,添加/启用了查看 Jira 问题数据查看用户配置文件选项

When trying to authenticate with the JIRA Cloud REST API, everything seems to work as expected.尝试使用 JIRA Cloud REST API 进行身份验证时,一切似乎都按预期工作。

  1. I begin by redirecting the user to authorise "App" to access data from JIRA via https://accounts.atlassian.com/authorize .我首先重定向用户以授权“应用程序”通过https://accounts.atlassian.com/authorize访问来自 JIRA 的数据。 I am including the following scope(s) in this request: offline_access read:jira-user read:jira-work to ensure required read access and the ability for token renewal (ie offline_access )我在此请求中包含以下范围: offline_access read:jira-user read:jira-work以确保所需的读取访问权限和令牌更新的能力(即offline_access

  2. On authorisation, I am redirected back to my application and request an access token via https://accounts.atlassian.com/oauth/token (using the provided redirect code ).获得授权后,我被重定向回我的应用程序并通过https://accounts.atlassian.com/oauth/token (使用提供的重定向code )请求访问令牌。 This succeeds, and I now have valid access_token and refresh_token 's这成功了,我现在有有效的access_tokenrefresh_token

  3. I now issue my first call to JIRA's Cloud REST API: https://api.atlassian.com/oauth/token/accessible-resources .我现在第一次调用 JIRA 的 Cloud REST API: https://api.atlassian.com/oauth/token/accessible-resources : https://api.atlassian.com/oauth/token/accessible-resources I use the access_token that was previously acquired to fetching my sites cloud_id via this call.我使用之前获得的access_token通过此调用获取我的网站cloud_id This works as expected and I now have my sites cloud_id这按预期工作,我现在有我的网站cloud_id

  4. I now try a seconds call to JIRA's Cloud REST API: https://api.atlassian.com/ex/jira/{MY_CLOUD_ID}/rest/api/3/search .我现在尝试调用 JIRA 的 Cloud REST API: https://api.atlassian.com/ex/jira/{MY_CLOUD_ID}/rest/api/3/search ://api.atlassian.com/ex/jira/{MY_CLOUD_ID}/rest/api/3/ https://api.atlassian.com/ex/jira/{MY_CLOUD_ID}/rest/api/3/search I use the access_token in the same way as before via these request headers:我通过这些请求标头以与以前相同的方式使用access_token

     headers: { 'Authorization': `Bearer { MY_ACCESS_TOKEN }`, 'Accept': 'application/json' }

The response I consistently get back is as follows:我一直得到的回应如下: 禁止 403。加载此页面时遇到 403 禁止错误。

As mentioned, this was working perfectly within the past week or so.如前所述,这在过去一周左右的时间内运行良好。 Unfortunately, the JIRA documentation doesn't list 403 as a response code for the search method .不幸的是,JIRA 文档没有列出403作为搜索方法的响应代码。

Two things ... (1) There was a post earlier this week where someone's search behavior in the cloud changed as well.两件事...... (1) 本周早些时候有一个帖子,其中有人在云中的搜索行为也发生了变化。 You may want to look for that post to see how it was resolved (I will look for it in a moment and if I find it, I'll add the link here).您可能想查找该帖子以了解它是如何解决的(我稍后会查找它,如果找到它,我会在此处添加链接)。 He was using "api/3" as are you ... the documentation says "api/3" is in beta.他和你一样使用“api/3”……文档说“api/3”处于测试阶段。 So maybe try with "api/2"?所以也许尝试使用“api/2”?

(2) I don't know if this code will help... it accesses the REST API but the calls I'm making are much different than yours. (2) 我不知道这段代码是否会有所帮助……它访问 REST API,但我所做的调用与您的调用大不相同。 This is against an on premise version of JIRA (up to date with the latest code).这是针对 JIRA 的内部部署版本(使用最新代码更新)。 I don't have a cloud instance to test against.我没有要测试的云实例。

Call for Logging in / Authentication:要求登录/认证:

Const APIAuthPath = "/rest/auth/1/session"


Sub Call_JIRALogin(pUserName, pPassword)

    Dim JIRASendString As String, JIRASendURL As String

    JIRASendURL = BaseURL1 & APIAuthPath

    JIRASendString = " {"
    JIRASendString = JIRASendString & Chr(34) & "username" & Chr(34) & ":" & Chr(34) & pUserName & Chr(34)
    JIRASendString = JIRASendString & ","
    JIRASendString = JIRASendString & Chr(34) & "password" & Chr(34) & ":" & Chr(34) & pPassword & Chr(34)
    JIRASendString = JIRASendString & "}"


    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    objHTTP.setOption 2, 13056


    With objHTTP
        .Open "POST", JIRASendURL, False
        .setRequestHeader "Content-Type", "application/json"
        .setRequestHeader "Accept", "application/json"
        .send (JIRASendString)
        CResponse1 = .responseText
        cCookie1 = "JSESSIONID=" & Mid(CResponse1, 42, 32) & "; Path=/Jira"  '*** Extract the Session-ID
        CStatus1 = .Status
    End With

Subsequent Calls:后续调用:

Sub BBB_SingleIssue_Driver(inIssueId)


    Dim JIRASendURL

    CurrIssue = inIssueId

    JIRASendURL = BaseURL1 & "/rest/api/2/issue/" & CurrIssue

    With objHTTP
        .Open "GET", JIRASendURL, False
        .setRequestHeader "Set-Cookie", cCookie1 '*** see Create a "Cookie"
        .send
        CResponse1 = .responseText
        CStatus1 = .Status
    End With

    If CStatus1 <> 200 Then
        MsgBox ("Failed to retrieve issue " & CurrIssue & "  status code : " & CStatus1)
        GlobalHttpStatus = CStatus1
        GlobalHttpResponse = CResponse1
        GlobalStep = "Retrieve Issue: " & CurrIssue
        GoTo SingleIssueErrOut
    End If

    '  handle a good response

SingleIssueErrOut:

    '  handle an error    

End Sub

The solution in the end was to use Basic Authentication via the Authorization header when issuing requests to JIRA's Cloud REST API:最终的解决方案是在向 JIRA 的 Cloud REST API 发出请求时通过Authorization标头使用基本身份验证

https://CLOUD_ID.atlassian.net/rest/api/3/API_METHOD   

Headers:标题:

'Authorization': 'Basic ZGFjcmVAb...',
'Accept': 'application/json'

Basic authentication will be removed in the future according to the API documentation , so this is being treated as a stop-gap solution. 根据 API 文档,未来将删除基本身份验证,因此这被视为权宜之计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM