I am developing an API, and recently I needed to test an authentication endpoint using the Bearer Token method. It made me think... why not share this process with the Dev Community using Thunder Client? I have already written an article about what Thunder Client is and how to use this VS Code extension, which you can find here.
Let’s see how you can easily test authentication with Thunder Client! 🚀
Credentials: Normally in APIs, authentication starts with a POST request using credentials like an email and password. In my case, I’m using an email and password in the request body, to send to the API endpoint “api/v1/Authentication”
My GitHub with this repository: repository-github
Receive the response: After sending the request, the API responds with important details such as an access token, its expiry date, and possibly user data. The most important here is the token.
Use the token for authentication: With the token in hand, you can make further requests to protected endpoints by passing the token in the request header. In this example, we’re working with Bearer Token Authentication. In my case, I will use the endpoint “api/v1/GetAllProducts” to test getting products
Add token in Thunder Client: Click on the Auth tab in Thunder Client, select "Bearer Token" from the options, and paste your token in the field, then click on "Send"
Now, we can see the response with the authorization
If the Bearer token is not passed, the return will be Unauthorized as in the example below.
That is for today, If you found this article helpful, please share and leave a comment.❤️
Top comments (0)