2

I just try to fetch general information from zapi api, but getting error Expecting claim 'qsh' to have value '7f0d00c2c77e4af27f336c87906459429d1074bd6eaabb81249e1042d4b84374' but instead it has the value '1c9e9df281a969f497d78c7636abd8a20b33531a960e5bd92da0c725e9175de9'

API LINK : https://prod-api.zephyr4jiracloud.com/connect/public/rest/api/1.0/config/generalinformation

can anyone help me please.

Ahsan Akhtar
  • 21
  • 2
  • 5

2 Answers2

2

I can definitely help you with this. You need to generate the JWT token in the right way.

package com.thed.zephyr.cloud.rest.client.impl;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.thed.zephyr.cloud.rest.ZFJCloudRestClient;
import com.thed.zephyr.cloud.rest.client.JwtGenerator;

public class JWTGenerator {

                public static void main(String[] args) throws URISyntaxException, IllegalStateException, IOException {
                                String zephyrBaseUrl = "https://prod-api.zephyr4jiracloud.com/connect";

                                String accessKey = "TYPE YOUR ACCESS KEY-GET IT FROM ZEPHYR";
                                String secretKey = "TYPE YOUR SECRET KEY-GET IT FROM ZEPHYR";
                                String userName = "TYPE YOUR USER - GET IT FROM ZEPHYR/JIRA";

                                ZFJCloudRestClient client = ZFJCloudRestClient.restBuilder(zephyrBaseUrl, accessKey, secretKey, userName).build();
                                JwtGenerator jwtGenerator = client.getJwtGenerator();

                                String createCycleUri = zephyrBaseUrl + "/public/rest/api/1.0/cycles/search?versionId=<TYPE YOUR VERSION ID HERE>&projectId=<TYPE YOUR PROJECT ID HERE>";

                                URI uri = new URI(createCycleUri);
                                int expirationInSec = 360;
                                String jwt = jwtGenerator.generateJWT("GET", uri, expirationInSec);
                                //String jwt = jwtGenerator.generateJWT("PUT", uri, expirationInSec);
                                //String jwt = jwtGenerator.generateJWT("POST", uri, expirationInSec);

                                System.out.println("FINAL API : " +uri.toString());
                                System.out.println("JWT Token : " +jwt);    

                }
 }

Also clone this repository: https://github.com/zephyrdeveloper/zfjcloud-rest-api which will give you all methods where respective encodings are there. You can build a Maven project to have these dependencies directly imported.

*I also spent multiple days to figure it out, so be patient and it's only the time till you generate right JWT.

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • This solution involves using some mystery `com.thed.zephyr` library rather than the Atlassian recommended one https://developer.atlassian.com/cloud/jira/platform/understanding-jwt-for-connect-apps/#java-example. I'd be curious to know how these 2 examples are different. – fmpdmb Jul 27 '21 at 18:24
2

The query string parameters must be sorted in alphabetical order, this will resolve the issue.
Please see this link for reference:
https://developer.atlassian.com/cloud/bitbucket/query-string-hash/

mskfisher
  • 3,291
  • 4
  • 35
  • 48