This guide walks you through a standard Postman workflow for JWT authentication APIs. We create a Postman environment to store credentials and tokens, and show the requests for register
, login
, profile
, refresh
, and logout
, and include test and pre-request scripts so Postman automatically manages the Authorization: Bearer {{token}}
header.
Step 1 — Create a Postman Environment
-
Go to Environments → Add in Postman.
-
Add these variables:
-
base_url
→http://localhost:8000/api
-
email
→test@example.com
-
password
→password123
-
token
→ (leave empty)
-
This environment will store your credentials and JWT token for all authentication requests.
Step 2 — Register a New User
-
POST
{{base_url}}/auth/register
-
Body → raw → JSON:
Registration is optional if you already have a user account.
Step 3 — Login to Get JWT
-
POST
{{base_url}}/auth/login
-
Body → raw → JSON:
-
Tests tab (save token):
This automatically saves the token in the environment variable
token
.
Step 4 — Get Authenticated User Profile
-
POST
{{base_url}}/auth/profile
-
Authorization → Bearer Token →
{{token}}
This endpoint uses the saved token to fetch user info.
Step 5 — Refresh JWT Token
-
POST
{{base_url}}/auth/refresh
-
Authorization → Bearer Token →
{{token}}
-
Tests tab:
Refresh ensures your token stays valid without logging in again.
Step 6 — Logout User
-
POST
{{base_url}}/auth/logout
-
Authorization → Bearer Token →
{{token}}
-
Tests tab (optional):
Logging out invalidates the token. Optionally, you can clear the environment variable.
Step 7 — Optional: Auto Refresh Token
Add this Pre-request Script at the collection level to automatically login if token is missing or expired:
Workflow Summary
-
Register (optional) → create a new user.
-
Login → save JWT token automatically.
-
Profile → use token to fetch user info.
-
Refresh → update the token if expired.
-
Logout → invalidate token and optionally clear variable.
Summary
Want the full source code?
Download the complete Laravel 12 JWT API Authentication example on my GitHub repo here.
Happy Coding!