Java 如何在addon REST Spring Atlassian Connect API中实现JWT授权?
我使用Java 如何在addon REST Spring Atlassian Connect API中实现JWT授权?,java,jira,Java,Jira,我使用 mvn archetype:generate -DarchetypeGroupId=com.atlassian.connect -DarchetypeArtifactId=atlassian-connect-spring-boot-archetype -DarchetypeVersion=1.5.1 atlassian-connect.json {... "scopes": [ "read", "write" ], "authentication": { "type": "jwt
mvn archetype:generate -DarchetypeGroupId=com.atlassian.connect -DarchetypeArtifactId=atlassian-connect-spring-boot-archetype -DarchetypeVersion=1.5.1
atlassian-connect.json
{...
"scopes": [
"read", "write"
],
"authentication": {
"type": "jwt"
},
"lifecycle": {
"installed": "/installed",
"uninstalled": "/uninstalled"
},
"enableLicensing": false,
"modules": {
"generalPages": [
{
"key": "comments",
"location": "system.top.navigation.bar",
"name": {
"value": "Comments"
},
"url": "/rest/api",
"conditions": [{
"condition": "user_is_logged_in"
}]
}
]
}
}
我正在尝试访问我的API
AJS.$.ajax({
url: "https://X.ngrok.io/rest/api",
type: "GET",
dataType: "json",
contentType: "application/json",
async: false, headers: {
'Authorization' : "JWT {{sessionToken}}"
},
success: function (data) {
console.log(e);
},
error: function(response) {
console.log(response);
}
})
如何在JS端获得jwt(最好描述
如果可以的话,请一步一步地使用简单的插件(我用示例检查了许多链接,但是…)您正在您的
atlassian connect.json
文件中声明一个HTML页面,即“注释”常规页面。因此,如果有人打开此页面,您可以生成JWT,并在将其返回给用户/请求者之前将其注入HTML文档。然后可以在JavaScript代码中使用此JWT。因为您似乎正在使用Spring引导模板,所以您应该看看中的“验证从iframe内容返回到加载项的请求”一节。这正是描述你的情况
另一个选项是基于从连接应用程序(如Jira或Confluence)接收的JWT生成JWT。然而,这是一个多一点的工作要做。我可以推荐阅读关于如何获得a以及它是如何工作的。基于这些,您可以生成自己的JWT
但是,在所有情况下,请注意不要为每个请求生成新令牌,而是为一个会话生成新令牌,这样您就可以将令牌用于多个请求。我建议使用选项a),因为Sprint引导连接模板已经支持它