发布到Jira Cloud API时出现Access-Control-Allow-Origin错误

时间:2018-12-14 20:58:26

标签: reactjs fetch jira jira-rest-api

我正在使用Jira的标准云API,但在使用其API来创建问题时遇到了麻烦。我已经尝试了基本身份验证和令牌身份验证,但都具有相同的CORS错误。

我已经按照这些文档(herehere)中列出的步骤进行操作,可以使该API在Postman中运行,但在我的React代码中不起作用。我认为这与邮递员不随请求发送预检选项有关。

以下是我的基本身份验证请求的示例:

fetch(`https://{DOMAIN}.atlassian.net/rest/api/3/issue/`, {
        method: "POST",
        credentials: 'include',
        headers: {
            "Content-Type": 'application/json',
            "Accept": 'application/json',
            "Authorization": "Basic {ENCODED USERNAME/PASSWORD}"
        },
        body: JSON.stringify(data)
})
.then(...)

这是我请求的令牌示例:

fetch(`https://{DOMAIN}.atlassian.net/rest/api/3/issue/`, {
        method: "POST",
        credentials: 'include',
        headers: {
            "Content-Type": 'application/json',
            "Accept": 'application/json',
            "Authorization": "bearer {TOKEN}"
        },
        body: JSON.stringify(data)
})
.then(...)

有人知道如何使用Jira Cloud API克服此CORS错误吗?我找到了这篇文章,但会假设问题已解决:https://jira.atlassian.com/browse/JRACLOUD-30371

更新

无法通过基本身份验证实现此功能,但是较新的OAuth 2.0可以运行(仅适用于GET请求)。

关注此堆栈溢出问题的更新:JIRA Cloud REST API (OAuth 2.0) Error 403 on POST Requests

0 个答案:

没有答案
相关问题