Skip to content

Instantly share code, notes, and snippets.

@crazyoptimist
Last active October 3, 2024 19:59
Show Gist options
  • Save crazyoptimist/b48671358a72e2857cfe0be33394a05e to your computer and use it in GitHub Desktop.
Save crazyoptimist/b48671358a72e2857cfe0be33394a05e to your computer and use it in GitHub Desktop.
Postman Script for JWT Login
// Locate the "Scripts" tab in Postman. Select "Post-response" left side tab. Copy, paste, and edit this script.
const jsonData = pm.response.json()
// Make sure necessary variables exist in the response
pm.test("Access Token exists", function () {
pm.expect(jsonData.access_token).to.not.equal(undefined);
});
pm.test("Refresh Token exists", function () {
pm.expect(jsonData.access_token).to.not.equal(undefined);
});
// Set store them as env vars, to make use of them in other requests
pm.environment.set("access_token", jsonData.access_token)
pm.environment.set("refresh_token", jsonData.refresh_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment