[英]JIRA Cloud REST API : Forbidden (403) error
我正在尝试在我正在开发的应用程序中使用 JIRA Cloud REST API。 最近我开始收到 403 错误。 直到大约一周前,我的集成都是可靠的,但是这些错误响应开始变得非常频繁。
我遵循了3LO code grants的文档。 目前,我有:
尝试使用 JIRA Cloud REST API 进行身份验证时,一切似乎都按预期工作。
我首先重定向用户以授权“应用程序”通过https://accounts.atlassian.com/authorize
访问来自 JIRA 的数据。 我在此请求中包含以下范围: offline_access read:jira-user read:jira-work
以确保所需的读取访问权限和令牌更新的能力(即offline_access
)
获得授权后,我被重定向回我的应用程序并通过https://accounts.atlassian.com/oauth/token
(使用提供的重定向code
)请求访问令牌。 这成功了,我现在有有效的access_token
和refresh_token
的
我现在第一次调用 JIRA 的 Cloud REST API: https://api.atlassian.com/oauth/token/accessible-resources
: https://api.atlassian.com/oauth/token/accessible-resources
。 我使用之前获得的access_token
通过此调用获取我的网站cloud_id
。 这按预期工作,我现在有我的网站cloud_id
我现在尝试调用 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
。 我通过这些请求标头以与以前相同的方式使用access_token
:
headers: { 'Authorization': `Bearer { MY_ACCESS_TOKEN }`, 'Accept': 'application/json' }
如前所述,这在过去一周左右的时间内运行良好。 不幸的是,JIRA 文档没有列出403
作为搜索方法的响应代码。
两件事...... (1) 本周早些时候有一个帖子,其中有人在云中的搜索行为也发生了变化。 您可能想查找该帖子以了解它是如何解决的(我稍后会查找它,如果找到它,我会在此处添加链接)。 他和你一样使用“api/3”……文档说“api/3”处于测试阶段。 所以也许尝试使用“api/2”?
(2) 我不知道这段代码是否会有所帮助……它访问 REST API,但我所做的调用与您的调用大不相同。 这是针对 JIRA 的内部部署版本(使用最新代码更新)。 我没有要测试的云实例。
要求登录/认证:
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
后续调用:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.