How do I get a JWT token to authorize scriptRunner for FlexNet Code Insight 6.8

How do I get a JWT token to authorize scriptRunner for FlexNet Code Insight 6.8

Summary

This article provides steps for getting a JWT token to authorize scriptRunner for FlexNet Code Insight 6.8.

Question

How do I get a JWT token to authorize scriptRunner for FlexNet Code Insight 6.8?

Answer

  1. Launch the web browser as a user who has Scripting Administrator privileges.

  2. After logging into the application, click on My Settings on the top right corner of the screen. Scroll to the bottom where you can add a Token.

    User-added image

  3. Proceed to add a token with a name to identify it, the desired expiration date, and copy the token as you will need it to run ScriptRunner.

    User-added image

  4. Navigate to the scriptRunner/bin directory to launch scriptRunner. You will need to The -c flag connects the core server, which needs to use the http(s) port used by the application, the same core server url specified in core.properties. Use the -u flag with the authorized user after you have copied the jwt Token from the Web UI.

    ./scriptRunner.sh -u username_of_scripting_administrator -c http(s)://core.server.url:8888/palamida/
  5. This will prompt you to enter the jwt Token, paste it in for the one time authorization. If the authorization is successful, the groovy commandline console will be launched. Exit the console with the command exit.

How to use JWT token while calling REST Apis

Here are couple of examples to use JWT token in a java REST client or javascript client.

RestClient.java

import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation.Builder;

public class RestClient {

    public static void connect() {
    String jwtToken = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImlhdCI6MTQ1MDM4Nzc5MH0.eIAZFqX9Mm5qlsHTjiztWBgT62RyDWPlBzp0phdgJaY";
    String target = "https://dev-linux-1.eng.palamida.com:8888/palamida/api/component/lookup componentNames=zlib&versionNames=1.2.8&forgeIds=175";
        Builder builder = ClientBuilder.newClient().target(target).request();
    builder.header("JWT_TOKEN", jwtToken);
        String result = builder.get().readEntity(String.class);
        System.out.println(result);
    }

}

rest-client.js

<\!DOCTYPE html>
<html>
  <head>
    <title>JWT Token Test</title>
    <script src="https://code.jquery.com/jquery-2.2.0.min.js" ></script>
    <script src="json-minified.js" ></script>
    <script>
      $(document).ready(function() {
    $("#zlib").click(function() {
      $.ajax({
        dataType: "json",
        type: "GET",
        beforeSend : function( xhr ) {
          xhr.setRequestHeader
           ("JWT_TOKEN", "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImlhdCI6MTQ1MDM4Nzc5MH0.eIAZFqX9Mm5qlsHTjiztWBgT62RyDWPlBzp0phdgJaY");
        },
        url: "https://dev-linux-1.eng.palamida.com:8888/palamida/api/component/lookup?componentNames=zlib&versionNames=1.2.8&forgeIds=175",
        success: function(data) {
          var obj = JSON.stringify(data);
          $('.c-data').append(obj);
        }
      })
    })
      });
    </script>
  </head>
  <body>
    <input type="button" id="zlib" value="Click to find component zlib data" />
    <p class="c-data"></p>
  </body>
</html>
Labels (1)
Was this article helpful? Yes No
No ratings
Version history
Revision #:
1 of 1
Last update:
‎Oct 22, 2018 04:08 PM
Updated by: