Hi, I am developing an Atlassian-connect addon. here I’m facing an issue while testing my JWT token to GET an issue with the rest API v3. I’m using python libraries of FLASK, atlassian-jwt and here is my code
i’m new to flask, python and atlassian app development. so please dont mind my noob skills
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)
Note that I took this code from the solution provided in this question. and modified it according to my needs. https://community.developer.atlassian.com/t/how-do-i-sign-my-jwt-requests-for-the-rest-interface/524/11
while this code returns a 404 client error, I have a couple of other questions as well.
- I’ve looked into some of the other solved questions and they suggested changes in the rest-API URL like
1.a instead of this
/rest/api/3/issue/issue_id
add Jira/ in front of URL which looks something like this
/jira/rest/api/3/issue/issue_id
However, this didn’t work as it says it is a dead link.
1.b instead of this
/rest/api/3/issue/issue_id
replace version 3 with ‘latest’
/rest/api/latest/issue/issue_id
This returned the same error
- When I installed the app in Jira, it returns a JSON which I’m trying to store in the dictionary, for the future purposes, but it says the dictionary is empty after some time
When installed:
{‘clientKey’: ‘value’, ‘sharedSecret’: ‘value’, ‘baseUrl’: ‘value’}
after some time:
{}
I want to know if it common or is there a way where I can store the JSON values until the app is down by me.