我尝试根据此文档将JWT签名的请求从Jira插件发送到Jira REST API https://developer.atlassian.com/cloud/jira/platform/understanding-jwt/
但是我收到任何尝试(GET / POST / PUT请求)的401响应。
我已经用这小段代码(JS,但是用Python手动尝试过)复制了它:
var jiraIdent = {
'key': 'com.xxxxxx.pharos',
'clientKey': 'a73bbba1-883a-3233-802b-417a7a4d2422',
'publicKey': 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/FRhHtTEpoNWWGcdcp4C5hhIvp/z7E91twOGB9BrXg3EgsjfHagvdwEOacCWVtY4gv6XwIDAQAB',
'sharedSecret': '41VtUH+LIQBakxtPlrsNS58qqVAlDVxxxxxxxxxxxxxxxxxxxxxxxxkBLDA6dtd7hdt4CDtbmLVpLNHRpPQ',
'serverVersion': '100109',
'pluginsVersion': '1.515.0',
'baseUrl': 'https://xxxxxxxxxxxxxx.atlassian.net',
'productType': 'jira',
'description': 'Atlassian JIRA at https://xxxxxxxxxxxxxx.atlassian.net ',
'eventType': 'installed'
}
var now = Math.floor(Date.now() / 1000),
exp = now + 10;
var url = jiraIdent.baseUrl + '/rest/api/2/issue/MTPC-2/properties/log';
console.log(url);
const req = jwt.fromMethodAndUrl('GET', url);
var jwtClaims = {
iss: jiraIdent.clientKey,
iat: now,
exp: exp,
qsh: jwt.createQueryStringHash(req)
};
console.log(jwtClaims);
var assertion = jwt.encode(jwtClaims, jiraIdent.sharedSecret);
console.log("Assertion:".yellow, assertion);
request.get({
url: url,
headers: {
"Accept": "application/json",
"Authorization": "JWT " + assertion
}
}, function(err, httpResponse, body) {
console.log('===============');
console.log(httpResponse.statusCode);
});
我已经检查了QSH-http://jwt-decoder.herokuapp.com/jwt/decode,它看起来与控制台中的一样,所以很好。我在安装握手期间收到“ clientKey”和“ sharedSecret”。
我将atlassian-connect.json中所有可能的作用域设置为对插件的高级访问权限。但是没有帮助。
我尝试了其他身份验证流(具有生成令牌的基本和Connect 应用https://developer.atlassian.com/cloud/jira/platform/user-impersonation-for-connect-apps/的用户模拟),它们可以正常工作,但不能运行JWT!
我没有其他想法