Search code examples
asp.net-web-api2asp.net-identitypostman

Using bearer authorization with PostMan


I am looking for an easy way to add bearer tokens to PostMan. I have imported my API into PostMan from a swagger definition, and am wondering if authorization can be added automatically to all requests in some easy way, such that I do not have to change the Authorization header for each endpoint whenever the token changes.

I am currently requesting a token at /token for my API by sending an x-www-form-urlencoded request containing the parameters username, password and grant_type with a password value.

The returned access_token is then appended to the Authorization header in the format "Bearer token-received-from-token-endpoint" for each request to the API.

The backend is implemented with AspNet Identity Framework and AspNet Web API 2.


Solution

  • Good approach here is chaining request

    When you get a token, assign it to an environment variable and use that variable in your subsequent requests. This way you will have a fresh token every time and your other requests can use that on runtime