【发布时间】:2018-03-19 14:30:14
【问题描述】:
我正在使用atlassian-connect-express 工具包来创建Atlassian Connect based Add-ons with Node.js.
它提供入站请求的自动 JWT 身份验证以及返回主机的出站请求的 JWT 签名。
当我在 JIRA 仪表板中安装插件并返回以下有效负载时,该插件已通过身份验证:
{ key: 'my-add-on',
clientKey: '*****',
publicKey: '********'
sharedSecret: '*****'
serverVersion: '100082',
pluginsVersion: '1.3.491',
baseUrl: 'https://myaccount.atlassian.net',
productType: 'jira',
description: 'Atlassian JIRA at https://myaccount.atlassian.net ',
eventType: 'installed' }
但我无法使用框架生成的 JWT 令牌对 JIRA Rest Api 进行身份验证。它会抛出以下错误消息。
404 '{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}'
以下是我发送 GET 请求时的代码:
app.get('/getissue', addon.authenticate(), function(req, res){
var request = require('request');
request({
url: 'https://myaccount.atlassian.net/rest/api/2/issue/ABC-1',
method: 'GET',
}, function(error, response, body){
if(error){
console.log("error!");
}else{
console.log(response.statusCode, body);
}
});
res.render('getissue');
});
下面是我的应用描述符文件的代码:
{
"key": "my-add-on",
"name": "Ping Pong",
"description": "My very first add-on",
"vendor": {
"name": "Ping Pong",
"url": "https://www.example.com"
},
"baseUrl": "{{localBaseUrl}}",
"links": {
"self": "{{localBaseUrl}}/atlassian-connect.json",
"homepage": "{{localBaseUrl}}/atlassian-connect.json"
},
"authentication": {
"type": "jwt"
},
"lifecycle": {
"installed": "/installed"
},
"scopes": [
"READ",
"WRITE"
],
"modules": {
"generalPages": [
{
"key": "hello-world-page-jira",
"location": "system.top.navigation.bar",
"name": {
"value": "Hello World"
},
"url": "/hello-world",
"conditions": [{
"condition": "user_is_logged_in"
}]
},
{
"key": "getissue-jira",
"location": "system.top.navigation.bar",
"name": {
"value": "Get Issue"
},
"url": "/getissue",
"conditions": [{
"condition": "user_is_logged_in"
}]
}
]
}
}
我很确定这不是我正在做的正确方式,要么我应该使用 OAuth。但我想在这里使用 JWT 方法进行身份验证。
【问题讨论】:
标签: node.js jira jira-rest-api jira-plugin