New in 2.4: Test runs you can trust See what's new →

Exchange a refresh token for new tokens

POSThttps://api.testingapis.com/api/auth/jwt/refresh

Refresh tokens are single use: each call returns a new one and the old one stops working. Presenting a refresh token that was already used is treated as theft: every refresh token from the same login is revoked, so the user has to log in again (reuse detection, RFC 9700).

Request body

Optional. application/json, text/json, application/*+json, application/xml, text/xml, application/*+xml. Model: JwtAuthControllerRefreshRequest. The refresh token to use.

Example body
{"refreshToken": "{{refreshToken}}"}

Responses

200
New access and refresh tokens.
400
refreshToken missing.
401
Refresh token invalid or expired, or already used (which also revokes its whole family).

Example

Request
curl -X POST "https://api.testingapis.com/api/auth/jwt/refresh" \
  -H "Content-Type: application/json" \
  -d '{"refreshToken": "{{refreshToken}}"}'
Run in Studio
Response200 OK
{
  "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI…
  "tokenType": "Bearer",
  "expiresIn": 900,
  "refreshToken": "jrt_b0f84f4f71e59e3231e4f56ae56a23c7bfa15f77",
  "user": {"username": "user", "role": "user", "name": "Uma User}
}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/auth/jwt/refresh", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: "{\"refreshToken\": \"{{refreshToken}}\"}",
});
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "POST",
    "https://api.testingapis.com/api/auth/jwt/refresh",
    headers={
        "Content-Type": "application/json",
    },
    data="{\"refreshToken\": \"{{refreshToken}}\"}".encode("utf-8"),
    allow_redirects=False,
)
print(response.status_code, response.text)
Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.testingapis.com/api/auth/jwt/refresh"))
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString("{\"refreshToken\": \"{{refreshToken}}\"}"))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}