首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React + Atlassian Cloud Api + Cors Anywhere:通过POST返回403添加工作日志

React + Atlassian Cloud Api + Cors Anywhere:通过POST返回403添加工作日志
EN

Stack Overflow用户
提问于 2018-07-20 20:42:17
回答 1查看 1.5K关注 0票数 1

被困在这上面好几天了。我正在制作一个使用亚特兰西安的Jira Cloud的React应用程序,我想从我的应用程序中记录Jira问题的工作。然而,每次我试一次,我都会得到403分。Postman中的相同请求工作,它创建工作日志,这是奇怪的。我设置了一个证书并使用cors-任何地方都可以在我的React应用程序中使用HTTPS,但否则查询是相同的。

我在亚特兰西安的论坛上读过一堆关于人们在需要发布到亚特兰的API时不确定该做什么的条目。这是什么奇怪的东西,无法修复,还是我缺少了一个相关的标题?

下面是我在React应用程序的ComponentDidMount()中进行的提取调用。https://localhost:8080是我为CORS-anywhere/Yarn使用的代理。

代码语言:javascript
复制
fetch("https://localhost:8080/my-domain.atlassian.net/rest/api/2/issue/ISSUE-1/worklog,{
            headers: {
              "Access-Control-Allow-Origin": "https://localhost:3000/",
              "X-Atlassian-Token": "no-check",
              "Content-Type": "application/json;charset=UTF-8",
              "Authorization": "Basic base64token",

            },
            method: "POST",
            responseType: 'json',
            body: {
                 "timeSpent":"2h 48m",
                 "author":{
                      "accountId":"123456789",      
                      "active":true,
                      "avatarUrls":{
                             "16x16":"https://avatar-cdn.atlassian.com/...",
                             "24x24":"https://avatar-cdn.atlassian.com/...",
                             "32x32":"https://avatar-cdn.atlassian.com/...",
                             "48x48":"https://avatar-cdn.atlassian.com/..."
                      },
                      "displayName":"User Name", 
                      "emailAddress":"user.name@gmail.com",
                      "key":"user.name",
                      "name":"user.name",
                      "self":"https://my-domain.atlassian.net/rest/api/2/user?username=user.name",
                      "timeZone":"Europe/Stockholm"
                  },
                  "comment":"bla bla bla",
                  "started":"2018-07-19T21:32:18.843+0200"
             }
        })
        .then((res) => res.json())
        .then(function(resJson){ 
            console.log(resJson
        })

这是亚恩运行的server.js。

代码语言:javascript
复制
const path = require('path')
const fs = require('fs')
const express = require('express')
const https = require('https')

const app = express();
const host = process.env.HOST || '0.0.0.0';
const port = process.env.PORT || 8080;

const cors_proxy = require('cors-anywhere');
cors_proxy.createServer({
    httpsOptions: {
        key: fs.readFileSync(path.resolve('server.key')),
        cert: fs.readFileSync(path.resolve('server.crt'))
    },
    originWhitelist: ['https://localhost:3000', 'https://localhost:8080'], 
    requireHeader: ['origin', 'x-requested-with'],
    removeHeaders: ['cookie', 'cookie2']
}).listen(port, host, function() {
    console.log('Running CORS Anywhere on ' + host + ':' + port);
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-22 20:30:09

您应该考虑构建亚特兰西安连接插件,而不是使用basic。您可以首先使用亚特兰-连接-快车,它将处理JWT令牌的附加和验证的安装。基本上,您将能够从服务器(用JWT令牌签名)进行安全调用,或者从前端(嵌入在Jira中)调用Jira API,这些调用将作为特定用户执行,这将生成适当的“由条目更新”。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51450092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档