Quantcast
Channel: Pochampalli IT Labs
Viewing all articles
Browse latest Browse all 261

How to set JWT Token as postman environment variable and use it for "Bearer Token" type in POST request Authorization

$
0
0

 Hi, 

Bearer token response body: 

{
"token_field1": "TokenField1ValueInEncodedFormat",
"token_lasts_for_howmanyms": 7200, //2 mins
"type_of_token": "Bearer"
}

Write below script in "Tests" tab of SOAP POST request (not in Pre-request scripts)

NOTE:
Token generated will get stored in VarJWTToken where VarJWTToken is an environment variable created in the environment.  
var data = JSON.parse(responseBody);
postman.clearEnvironmentVariable(
"VarJWTToken");
postman.setEnvironmentVariable(
"VarJWTToken", data.token_field1);

Use the VarJWTToken environment variable in request Authorization as shown in below image: 
Postman collection format: 
Token  (Token generated in this request will get stored in environment variable)
   SOAP POST Request (using environment variable POST authentication will be done) 

Viewing all articles
Browse latest Browse all 261

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>