Guest User

Untitled

a guest
Jan 24th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. # How to automatically set a Bearer Token for your Postman requests
  2.  
  3. ### 1. Create `access_token` variables
  4. i. Click `Manage Environments` on the right side of postman application.
  5.  
  6. ii. Add new environment and insert `access_token` keyword under `VARIABLE` field only.
  7.  
  8. ### 2. Create Authentication API
  9. i. Insert `your oauth url` with `POST` method.
  10.  
  11. ii. Click Headers tab and set the key parameter (depends on your):-
  12. ```
  13. Content-Type : application/x-www-form-urlencoded
  14. ```
  15. ```
  16. Authorization : Basic <<secret>>
  17. ```
  18.  
  19. iii. Click Body tab and set the key parameter:-
  20. ```
  21. grant_type : password
  22. ```
  23. ```
  24. username : <<secret>>
  25. ```
  26. ```
  27. password : <<secret>>
  28. ```
  29.  
  30. iv. Select the environment name that we create in `Step 1`.
  31.  
  32. ### 3. Create Tests script
  33. i. Click `Tests` tab and put this code:-
  34. ```
  35. var data = pm.response.json();
  36. pm.environment.set("access_token", data.access_token);
  37. ```
  38.  
  39. ### 4. Create a new API
  40. i. Select the environment name that we create in `Step 1`.
  41.  
  42. ii. Insert the API URL and the method.
  43.  
  44. iii. make sure the API already save in postman.
  45.  
  46. iii. Click Headers tab and set the key parameter:-
  47.  
  48. ```
  49. Authorization: Bearer {{access_token}} // Choose the variable name we create in Step 1
  50. ``` `
Add Comment
Please, Sign In to add comment