Skip to content

Instantly share code, notes, and snippets.

@kai-chi
Last active November 14, 2019 10:59
Show Gist options
  • Save kai-chi/3a2cff45e5e8df6b64b63a630bf6cabf to your computer and use it in GitHub Desktop.
Save kai-chi/3a2cff45e5e8df6b64b63a630bf6cabf to your computer and use it in GitHub Desktop.
Postman Pre-request Script for setting Hopsworks JWT token

To automatically set jwt token before a request:

  1. In "Authorization" tab - set "No Auth"
  2. In "Headers" tab - add header with key "Authorization" and value "{{Authorization}}"
  3. You can set a script for the whole collection/folder/single request. To set it for every single request from the collection right-click on the collection name and "Edit". Go to "Pre-request Scripts" tab and paste:
    pm.sendRequest({
        url: "https://localhost:8181/hopsworks-api/api/auth/login",
        method: 'POST',
        header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: {
            mode: 'urlencoded',
            urlencoded: [
                {key: "email", value: "admin@hopsworks.ai"},
                {key: "password", value: "admin"}
            ]
        }
    }, function (err, res) {
        pm.globals.set("Authorization", res.headers.get("Authorization"));
    });
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment