JIRA Cloud REST API:禁止 (403) 错误
JIRA Cloud REST API : Forbidden (403) error
我正在尝试在我正在开发的应用程序中使用 JIRA Cloud REST API。最近我开始收到 403 错误。直到大约一周前,我的集成都是可靠的,但是这些错误响应开始变得非常频繁。
我已遵循 3LO code grants 的文档。目前,我有:
- 在 application dashboard
下安装了一个名为 "App" 的应用程序
- 在应用程序仪表板中,我的 "App" 可以访问 "Jira platform REST API" 和 "Authorization code grants"
- 在 "Jira platform REST API" 下,对于我的 "App",查看 Jira 问题数据 和 查看用户配置文件 选项是added/enabled
尝试使用 JIRA Cloud REST API 进行身份验证时,一切似乎都按预期进行。
我首先重定向用户以授权 "App" 通过 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
。我使用之前获得的 access_token
通过此调用获取我的网站 cloud_id
。这按预期工作,我现在有了我的网站 cloud_id
我现在尝试对 JIRA 的 Cloud REST 进行秒调用 API:https://api.atlassian.com/ex/jira/{MY_CLOUD_ID}/rest/api/3/search
。我通过这些请求 headers:
以与以前相同的方式使用 access_token
headers: {
'Authorization': `Bearer { MY_ACCESS_TOKEN }`,
'Accept': 'application/json'
}
我一直收到的回复如下:
如前所述,这在过去一周左右的时间里运行良好。不幸的是,JIRA 文档没有将 403
列为 search method.
的响应代码
两件事... (1) 本周早些时候 post 某人在云中的搜索行为也发生了变化。您可能想查找 post 以查看它是如何解决的(我稍后会查找它,如果找到它,我将在此处添加 link)。他和你一样使用 "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
最终的解决方案是在向 JIRA 的 Cloud REST API:
发出请求时通过 Authorization
header 使用 Basic Authentication
https://CLOUD_ID.atlassian.net/rest/api/3/API_METHOD
Headers:
'Authorization': 'Basic ZGFjcmVAb...',
'Accept': 'application/json'
将来 according to the API documentation 将删除基本身份验证,因此这被视为 stop-gap 解决方案。
我正在尝试在我正在开发的应用程序中使用 JIRA Cloud REST API。最近我开始收到 403 错误。直到大约一周前,我的集成都是可靠的,但是这些错误响应开始变得非常频繁。
我已遵循 3LO code grants 的文档。目前,我有:
- 在 application dashboard 下安装了一个名为 "App" 的应用程序
- 在应用程序仪表板中,我的 "App" 可以访问 "Jira platform REST API" 和 "Authorization code grants"
- 在 "Jira platform REST API" 下,对于我的 "App",查看 Jira 问题数据 和 查看用户配置文件 选项是added/enabled
尝试使用 JIRA Cloud REST API 进行身份验证时,一切似乎都按预期进行。
我首先重定向用户以授权 "App" 通过
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
。我使用之前获得的access_token
通过此调用获取我的网站cloud_id
。这按预期工作,我现在有了我的网站cloud_id
我现在尝试对 JIRA 的 Cloud REST 进行秒调用 API:
以与以前相同的方式使用https://api.atlassian.com/ex/jira/{MY_CLOUD_ID}/rest/api/3/search
。我通过这些请求 headers:access_token
headers: { 'Authorization': `Bearer { MY_ACCESS_TOKEN }`, 'Accept': 'application/json' }
我一直收到的回复如下:
如前所述,这在过去一周左右的时间里运行良好。不幸的是,JIRA 文档没有将 403
列为 search method.
两件事... (1) 本周早些时候 post 某人在云中的搜索行为也发生了变化。您可能想查找 post 以查看它是如何解决的(我稍后会查找它,如果找到它,我将在此处添加 link)。他和你一样使用 "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
最终的解决方案是在向 JIRA 的 Cloud REST API:
发出请求时通过Authorization
header 使用 Basic Authentication
https://CLOUD_ID.atlassian.net/rest/api/3/API_METHOD
Headers:
'Authorization': 'Basic ZGFjcmVAb...',
'Accept': 'application/json'
将来 according to the API documentation 将删除基本身份验证,因此这被视为 stop-gap 解决方案。