Hello,
I created an AWS Lambda function. I have successfully installed it in Jira via manifest. According to the documentation, I implemented JWT token creation. I use this token to communicate one-way with Jira. I don’t have any webhooks. My goal is to make an entry in the Issue worklog. However, when I make a request to, for example, /rest/api/3/myself, I still get a 401 status. I’ve been fighting this for three days. Can anyone advise me or verify if I have the correct implementation of creating a token and calling the endpoint?
My JWT token generation (Python):
def generate_jwt_token(self, url, method, query_params=None):
# # Nastav údaje pre token
issued_at = int(time.time())
expires_at = issued_at + 120 # 2 minutes
payload = {
"iss": manifest["key"], #com.solvedio.<myapp>
"iat": issued_at,
"exp": expires_at,
"qsh": self.generate_query_hash(url, method, query_params),
"aud": self.secret.base_url #https://<mytenant>.atlassian.net
}
# Sign it with sharedSecret
return jwt.encode(payload, self.secret.shared_secret, algorithm="HS256")
def generate_query_hash(self, url, method, query_params=None):
parsed_url = urlparse(url)
path = parsed_url.path
canonical_url = f"{method.upper()}&{path}"
if query_params:
sorted_query = "&".join(f"{k}={v}" for k, v in sorted(query_params.items()))
canonical_url += f"&{sorted_query}"
canonical_url += "&"
return hashlib.sha256(canonical_url.encode('utf-8')).hexdigest()
My calling of endpoint:
def check_me(self):
url = f"{self.security.secret.base_url}/rest/api/3/myself"
token = self.security.generate_jwt_token(url, "GET")
headers = {
"Authorization": f"JWT {token}",
"Accept": "application/json",
"X-Atlassian-Token": "no-check"
}
response = requests.get(url, headers=headers)
if response.status_code == 200 and response.json():
return {
'statusCode': 200,
'body': response.json()
}
else:
return {
'statusCode': response.status_code,
'body': json.dumps({
"headers": headers,
"url": url,
"message" : response.text,
}
)
}
My installation manifest:
manifest = {
"name": "My connector",
"description": "Atlassian Connect app (bridge between Me and Jira)",
"key": "com.solvedio.myconnector",
"baseUrl": "<Url of Lambda function>",
"vendor": {
"name": "Solvedio",
"url": "https://solvedio.com/"
},
"authentication": {
"type": "jwt"
},
"lifecycle": {
"installed": "/installed",
"uninstalled": "/uninstalled"
},
"scopes": ["read", "write"],
"apiVersion": 3,
"modules": {
}
}
Thank you.