Correct the sequence numbers for logout and refresh token tests. Add sample registration data to the Register User test.
81 lines
2.0 KiB
YAML
81 lines
2.0 KiB
YAML
info:
|
|
name: Refresh Access Token
|
|
type: http
|
|
seq: 4
|
|
|
|
http:
|
|
method: POST
|
|
url: "{{base_url}}/api/auth/refresh"
|
|
headers:
|
|
- name: ""
|
|
value: application/json
|
|
body:
|
|
type: json
|
|
data: ""
|
|
auth: inherit
|
|
|
|
runtime:
|
|
scripts:
|
|
- type: after-response
|
|
code: |-
|
|
function onResponse(res) {
|
|
try {
|
|
const responseBody = res.getBody();
|
|
const token = responseBody.access_token;
|
|
const refreshToken = responseBody.refresh_token;
|
|
|
|
if (token) {
|
|
bru.setEnvVar("token", token, { persist: true });
|
|
console.log("Access token saved:", token);
|
|
}
|
|
|
|
if (refreshToken) {
|
|
bru.setEnvVar("refresh_token", refreshToken, { persist: true });
|
|
console.log("Refresh token saved:", refreshToken);
|
|
}
|
|
|
|
if (!token && !refreshToken) {
|
|
console.log("No tokens found in response.");
|
|
}
|
|
} catch (error) {
|
|
console.error("Error in post-response script:", error.message);
|
|
}
|
|
}
|
|
onResponse(res);
|
|
|
|
settings:
|
|
encodeUrl: true
|
|
timeout: 0
|
|
followRedirects: true
|
|
maxRedirects: 5
|
|
|
|
docs: |-
|
|
## Refresh Access Token
|
|
|
|
Refreshes an access token using a valid refresh token. Returns a new access token with 1-hour expiration.
|
|
|
|
**Method:** POST
|
|
|
|
**Endpoint:** /api/auth/refresh
|
|
|
|
**Authentication:** Not required (refresh token is in request body)
|
|
|
|
**Request Body:**
|
|
- `refresh_token` (string): Valid refresh token UUID
|
|
|
|
**Response:**
|
|
- `access_token` (string): New JWT access token (1 hour expiration)
|
|
- `token_type` (string): Token type (usually "Bearer")
|
|
- `expires_in` (number): Token lifetime in seconds (3600)
|
|
|
|
**Status Codes:**
|
|
- 200: Success - new access token generated
|
|
- 401: Unauthorized - invalid or expired refresh token
|
|
|
|
**Example Response (Success):**
|
|
```json
|
|
{
|
|
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
"token_type": "Bearer",
|
|
"expires_in": 3600
|