调用ZAPI(Jira Zephyr API)时以我的JWT令牌作为响应获取401

时间:2019-07-17 21:50:13

标签: node.js jira-rest-api jira-zephyr

我根据以下线程生成JWT令牌:https://support.getzephyr.com/hc/en-us/community/posts/115010528066-JWT-Generation-with-Node。我必须进行一些小的修改,因为自从GDPR更新以来,似乎我们必须传递ACCOUNTID而不是用户名。

访问密钥和秘密密钥来自JIRA中的Zapi插件(我刚刚安装(2019/07/17)。我不是管理员用户。

function generateToken() {

    let now = moment().utc();

// this come from the profile section in jira: //https://powerfactors.atlassian.net/people/<my acccout id>
    let USER = '<my acccout id>'; 

    let ACCESS_KEY = '<MY ACCESS KEY>';

    let SECRET_KEY = '<MY SECRET KEY>';

    let IAT = now.unix();

    let EXP = now.add(3, 'minutes').unix();


    let req = {
      method: 'GET',
      originalUrl: '/public/rest/api/1.0/config/generalinformation'
      };

    let QSH = jwt.createQueryStringHash(req);


    let payload = {
    'exp' : EXP,
    'iat' : IAT,
    'iss' : ACCESS_KEY,
    'qsh' : QSH,
    'sub' : USER
    };

    return jwt.encode(payload, SECRET_KEY);
}
async function getServerInfo(token: string, base_url: string) {
  const headers = {
  'Content-Type': 'text/plain',
  Authorization: `JWT ${token}`,
  zapiAccessKey: '<my access key>',
  };

  const uri = `${base_url}/public/rest/api/1.0/config/generalinformation`

  let options = {
  method: 'GET',
  uri,
  headers
  };

  return await Commons.rest_call(options);
}
  let BASE_URL = 'https://prod-api.zephyr4jiracloud.com/connect';
  console.log(await getServerInfo(generateToken(), BASE_URL));

我希望获得常规配置,但我会打印我的JWT令牌作为响应。

0 个答案:

没有答案