Auth

Last updated 2026-05-20

Mock login endpoint that returns a JWT-style access token plus the authenticated user payload. Includes refresh-token and "get auth user" examples. Live endpoint at /auth/login.

Auth

fetch('https://jsonexamples.com/auth/login', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    /* any username/password from users module */
    username: 'kminchelle',
    password: '0lelplR',
    expiresInMins: 30, // optional, defaults to 60
  })
})
  .then(res => res.json())
  .then(console.log);
Response
{
  "id": 15,
  "username": "kminchelle",
  "email": "[email protected]",
  "firstName": "Jeanne",
  "lastName": "Halvorson",
  "gender": "female",
  "image": "https://robohash.org/Jeanne.png?set=set4",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTUsInVzZXJuYW1lIjoia21pbmNoZWxsZSIsImlhdCI6MTcxMTIwOTAwMSwiZXhwIjoxNzExMjEyNjAxfQ.F_ZCpi2qdv97grmWiT3h7HcT1prRJasQXjUR4Nk1yo8"
}
/* providing token in bearer */
fetch('https://jsonexamples.com/auth/me', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer /* YOUR_TOKEN_HERE */',
  },
})
  .then(res => res.json())
  .then(console.log);
Response
{
  "id": 15,
  "username": "kminchelle",
  "email": "[email protected]",
  "firstName": "Jeanne",
  "lastName": "Halvorson",
  "gender": "female",
  "image": "https://robohash.org/Jeanne.png?set=set4"
  // ...other user fields
}
  • Extend the session and create a new token without username and password.
fetch('https://jsonexamples.com/auth/refresh', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer /* YOUR_TOKEN_HERE */',
  },
  body: JSON.stringify({
    expiresInMins: 30, // optional, defaults to 60
  })
})
  .then(res => res.json())
  .then(console.log);
Response
{
  "id": 15,
  "username": "kminchelle",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  // ...other user fields
}

Related examples