title: Postman Pre-Request Script to create JWT for Google Service Account
body: <p>I am trying to create a JWT to get an access token for a Google Service Account to use in a Postman Pre-Request script.</p>
  
  <p>But I keep getting this error in the Postman Console: </p>
  
  <pre><code>Error:
  </code></pre>
  
  <p>And in the Postman Response window I get: </p>
  
  <pre><code>There was an error in evaluating the Pre-request Script:  undefined: undefined
  </code></pre>
  
  <p>I localized the error to be failing here:</p>
  
  <pre><code>var jwt = KJUR.jws.JWS.sign(null, header, claimSet, privateKey);
  </code></pre>
  
  <p>I'm importing it by using a request to <code>http://kjur.github.io/jsrsasign/jsrsasign-latest-all-min.js</code> and saving it to an environment variable called <code>jsrsasign</code>  then rehydrating it below with eval. </p>
  
  <p>Pre-Request Script: </p>
  
  <pre><code>var navigator = {};
  var window = {};
  eval(pm.environment.get("jsrsasign"));
  
  var scope = pm.environment.get('scope');
  var iss = pm.environment.get('iss');
  var privateKey = pm.environment.get('privateKey');
  
  const header = {"alg" : "RS256", "typ" : "JWT"};
  
  const claimSet =
  {
    "iss": iss,
    "scope": scope,
    "aud":"https://oauth2.googleapis.com/token",
    "exp":KJUR.jws.IntDate.get("now + 1hour").toString(),
    "iat": KJUR.jws.IntDate.get("now").toString()
  }
  
  console.log(`header: ${ JSON.stringify(header)}`);
  console.log(`claim set: ${ JSON.stringify(claimSet) }`);
  
  var jwt = KJUR.jws.JWS.sign(null, header, claimSet, privateKey);
  
  pm.environment.set('jwt', jwt);
  </code></pre>
  
  <p>Similar issue to this guy's comment on Medium: 
  <a href="https://medium.com/@jkohne/hi-klaasjan-tukker-im-trying-to-get-the-library-import-and-eval-to-work-for-jsrsasign-c0c457ddd23f" rel="nofollow noreferrer">https://medium.com/@jkohne/hi-klaasjan-tukker-im-trying-to-get-the-library-import-and-eval-to-work-for-jsrsasign-c0c457ddd23f</a></p>