postmonkey
Don't monkey around in Postman scripts! Use Postmonkey! Postmonkey gives you custom scripts to use in
Getting Started Guide
If you want to build this code just run yarn run build
, that will build you the development mode of the bundle
and publish it to dist/bundle.js
.
If you then want to use this code you can start a node
environment and:
pm;
And that is it, now you have this script running. The most important step, from here, will be to have this script included in a postman variable so that it can be loaded at runtime.
Postmonkey ASAP API
generateAsapToken
Generates an ASAP token from the given asap key data. The output is a JWT token complying with the Atlassain Service Authentication Protocol specification, which may be used as a Bearer token for ASAP authenticated endponts.
Syntax
postmonkeyasap;
Parameters
asapData (Required)
Object with ASAP configuration data. The raw data should come from a .asap-config
file generated by the asap init
CLI command.
additionalClaims (Optional)
Object with additional key/value pairs to be included as properties in the JWT token.
parseAdditionalClaims
Parses an input string to create an object with key/value pairs representing additional claims to be included in an ASAP token.
Syntax
postmonkeyasap;
Parameters
input Required
A comma separated string of key=value
pairs, or a JSON object. If using the key=value
syntax, if the =value
is omitted, the default value is undefined.
Using key=value
syntax:
accountId=490f8eb7-30df-4d5c-8129-9a617b8884aa,cloudId=7abe7b98-3879-4a63-8228-053b5e041e0f
Or JSON:
If the input
value, ignoring whitespace, begins with {
, then the value will be parsed using JSON.parse()
. Otherwise, the value will be parsed as key=value
pairs.
reviver Optional
A function that transforms the original parsed value into any desired value. The reviver function must be compatible with the reviver
parameter for JSON.parse()
. The function will be invoked with the key
and value
parameters. The return value will be assigned to the property. The function will be invoked with this
set to the result object.
For example, if a particular value is omitted from the input, a reviver function may be used to obtain a value from Postman variables based on the key. The reviver may also be used to interpolate Postman variable strings.
Example Reviver Function
This reviver function will interpolate Postman variables, and recursively parse JSON values.
{ const revived = pmvariables; if typeof revived === 'string' && /^\s*\s*$/ return JSON; return revived;};
Example Usage
Postman Variables
Variable | Value |
---|---|
.asap-config | (see code block below) |
additionalClaims | accountId,cloudId={{cloudId-staging}} |
accountId | 490f8eb7-30df-4d5c-8129-9a617b8884aa |
cloudId-staging | 7abe7b98-3879-4a63-8228-053b5e041e0f |
iss | micros/dev |
sub | {{iss}} (Makes this equal to the issuer) |
kid | micros/dev/example |
audience | ["identity-platform","perms"] |
asap-private.pem | -----BEGIN RSA PRIVATE KEY-----UG9zdG1vbmtleUpT...-----END RSA PRIVATE KEY----- |
.asap-conifg
Using this script, with the above reviver function, the token ASAP config and additionalClaims will be parsed with correctly interpolated Postman variables.
const asapConfig = JSON; const additionalClaims = postmonkeyasap; const token = postmonkeyasap; pmrequestheaders;