如何为JIRA API生成jwt标记

我正在尝试生成jwt令牌以授权API。 首先,我找不到JIRA的任何令牌生成器api。 经过大量搜索后,我找到了一个生成jwt令牌的java代码,但是在导入zephyr库时会出错。

错误:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script4.groovy: 18: unable to resolve class com.thed.zephyr.cloud.rest.ZFJCloudRestClient @ line 18, column 1. import com.thed.zephyr.cloud.rest.ZFJCloudRestClient; 

Java代码:

 https://github.com/zephyrdeveloper/zapi-cloud/blob/master/Samples/src/com/thed/zapi/cloud/sample/sampleJwtGenerator.java 

我使用SoapUI Groovy脚本为ZAPI生成JWT令牌。

注意 :

  1. 库版本应该是lib文件夹中的’commons-lang-2.6.jar’和’commons-codec-1.11.jar’。

  2. 在bin – > ext文件夹中添加’jwt-generator.jar’和’zfj-cloud-rest-client-3.0.jar’。 jwt发电机

  3. 将创建特定于输入的API URL的JWT令牌。 例如:

    String createCycleUri = zephyrBaseUrl +“/ public /rest / api / 1.0 / cycle”;

  4. 在生成jwt令牌之前提及api HTTP方法类型。

    String jwt = jwtGenerator.generateJWT(“POST”,uri,expirationInSec);

  5. 任何ZAPI api的站点始终固定。 这将采用JWT令牌。

https://prod-api.zephyr4jiracloud.com/connect

文件中提到了哪一个。

https://zfjcloud.docs.apiary.io/#

  1. 如果您使用下面文档中提到的JIRA api,将使用您创建的站点URL。 这将采用基本的Auth。

https://getzephyr.docs.apiary.io/#

例如:

https://newapi.atlassian.net

Groovy:

 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; def site = context.expand( '${#Project#Site}' ) def zapiAccessKey = context.expand( '${#Project#zapiAccessKey}' ) def secretID = context.expand( '${#Project#secretID}' ) def user = context.expand( '${#Project#user}' ) // Replace Zephyr BaseUrl with the  shared with ZAPI Cloud Installation String zephyrBaseUrl = site; // zephyr accessKey , we can get from Addons >> zapi section String accessKey = zapiAccessKey; // zephyr secretKey , we can get from Addons >> zapi section String secretKey = secretID; // Jira UserName String userName = user; ZFJCloudRestClient client = ZFJCloudRestClient.restBuilder(zephyrBaseUrl, accessKey, secretKey, userName).build(); JwtGenerator jwtGenerator = client.getJwtGenerator(); // API to which the JWT token has to be generated String createCycleUri = zephyrBaseUrl + "/public/rest/api/1.0/cycle"; URI uri = new URI(createCycleUri); int expirationInSec = 3600; String jwt = jwtGenerator.generateJWT("POST", uri, expirationInSec); log.info "JWT Token : " + jwt //Store token in property. context.testCase.testSuite.project.setPropertyValue('JWT_Token', jwt)