我正在开发Atlassian-connect插件。在测试我的JWT令牌以解决其余API v3的问题时,我遇到了一个问题。我正在使用FLASK,atlassian-jwt的python库,这是我的代码
我是Flask,Python和Atlassian应用程序开发的新手。所以请不要介意我的菜鸟技能:sweat_smile:
import atlassian_jwt
import requests
from flask import Flask, request, jsonify, redirect, render_template
ADDON_KEY = "ADDON_KEY "
clients = {}
if __name__ == '__main__':
app = Flask(__name__)
# App descriptor
descriptor = {
"modules": {},
"name": "my connect app",
"description": "Atlassian Connect app",
"key": "my connect app-V1",
"baseUrl": "ngrok url",
"vendor": {
"name": "Example, Inc.",
"url": "http://example.com"
},
"lifecycle": {
"installed": "/register",
},
"authentication": {
"type": "jwt"
},
"apiVersion": 1,
"modules": {
"generalPages": [
{
"url": "/what.html",
"key": "hello-world",
"location": "system.top.navigation.bar",
"name": {
"value": "Index page"
}
}
]
},
"scopes": [
"read",
"write"
]
}
class SimpleAuthenticator(atlassian_jwt.Authenticator):
def get_shared_secret(self, client_key):
return clients[client_key]['sharedSecret']
auth = SimpleAuthenticator()
@app.route('/', methods=['GET'])
def redirect_to_descriptor():
return redirect('/descriptor')
@app.route('/descriptor', methods=['GET'])
def get_descriptor():
print("descriptor triggered: \n",
jsonify(descriptor))
return jsonify(descriptor)
@app.route('/register', methods=['POST'])
def register():
print("route triggered")
global clients
client = request.get_json()
# clients[client['clientKey']] = client
clients['clientKey'] = client['clientKey']
clients['sharedSecret'] = client['sharedSecret']
clients['baseUrl'] = client['baseUrl']
print(clients['baseUrl'], " : ", client['baseUrl'])
return ' ', 204
@app.route('/what.html', methods=['GET','POST'])
def main_page():
print("\n What method triggeted")
return render_template('ind.html')
@app.route('/ping', methods=['GET','POST'])
def ping():
print("Ping method triggered")
print("\n ", clients, "\n")
ping_url =' /rest/api/3/issue/issue_id'
jwt_authorization = atlassian_jwt.encode_token('GET', ping_url ,clientKey =
clients['clientKey'],sharedSecret= clients['sharedSecret'])
print("\n JWT KEY: ", jwt_authorization,"\n")
result = requests.get(clients['baseUrl'].rstrip('/') + ping_url, headers={'Authorization':
jwt_authorization})
result.raise_for_status()
print(result.status_code, result.json())
print("end Ping method")
return ' ', 204
app.run(host='127.0.0.1',port=8000,debug=True)
Error: requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://mydomain.atlassian.net/jira/rest/api/latest/issue/issue_id
虽然此代码返回404客户端错误,但我还有其他几个问题。
/ rest / api / 3 / issue / issue_id
在看起来像这样的URL前面添加Jira /
/ jira / rest / api / 3 / issue / issue_id
但是,这没有用,因为它说这是一个死链接。
1.b代替
/ rest / api / 3 / issue / issue_id
将版本3替换为“最新”
/ rest / api / latest / issue / issue_id
这返回了相同的错误
{'clientKey':'值','sharedSecret':'值','baseUrl':'值'}
一段时间后:
{}
我想知道这是普遍的还是有一种方法可以存储JSON值,直到我关闭应用程序为止。