hellinodreman
4 years agoNew Contributor
JWT generation
I am trying to generate a JWT using python. I followed the given example in the documentation, but I always get error 400.
I am using the following code:
# BASE URL for Zephyr for Jira Cloud
BASE_URL = 'https://prod-api.zephyr4jiracloud.com/connect'
# RELATIVE PATH for token generation and make request to api
RELATIVE_PATH = '/public/rest/api/1.0/cycle'
# CANONICAL PATH (Http Method & Relative Path & Query String)
CANONICAL_PATH = 'POST&'+RELATIVE_PATH+'&'
# TOKEN HEADER: to generate jwt token
payload_token = {
'sub': ACCOUNT_ID,
'qsh': hashlib.sha256(CANONICAL_PATH.encode('utf-8')).hexdigest(),
'iss': ACCESS_KEY,
'exp': int(time.time())+JWT_EXPIRE,
'iat': int(time.time())
}
# GENERATE TOKEN
token = jwt.encode(payload_token, SECRET_KEY, algorithm='HS256').strip()
headers = {
'Content-Type': 'application/json',
'Authorization': 'JWT '+token,
'zapiAccessKey': ACCESS_KEY
}
# REQUEST PAYLOAD: to create cycle
cycle = {
'name': 'Sample Cycle',
'projectId': '10200',
'versionId': '5.X'
}
raw_result = requests.post(BASE_URL + RELATIVE_PATH, headers=headers, json=cycle)
Could anyone tell me what I'm doing wrong?