Auth Authentication

Simulate login flows with JWT tokens. Use any mock user's credentials to test.

Login user

Login to get an access token. You can use any mock user's username and password from the Users API.
fetch('https://axomock.fauzantaslim.biz.id/api/auth/login', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    username: 'hbingley1',
    password: 'CQutx25i8r'
  })
})
.then(res => res.json())
.then(console.log);
axios.post('https://axomock.fauzantaslim.biz.id/api/auth/login', {
  username: 'hbingley1',
  password: 'CQutx25i8r'
})
.then(res => console.log(res.data));
curl -X POST https://axomock.fauzantaslim.biz.id/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"hbingley1","password":"CQutx25i8r"}'
200 OK
{
  "id": 2,
  "username": "hbingley1",
  "email": "hbingley1@plala.or.jp",
  "firstName": "Hugh",
  "lastName": "Bingley",
  "image": "https://robohash.org/Hugh.png",
  "token": "eyJhbGciOiJIUzI1NiIsInR...",
  "refreshToken": "a1b2c3d4e5f6..."
}

Get auth user

Get the currently authenticated user. Requires a valid JWT token in the Authorization: Bearer <token> header.
fetch('https://axomock.fauzantaslim.biz.id/api/auth/me', {
  headers: { 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR...' }
})
.then(res => res.json())
.then(console.log);
axios.get('https://axomock.fauzantaslim.biz.id/api/auth/me', {
  headers: { 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR...' }
})
.then(res => console.log(res.data));
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR..." https://axomock.fauzantaslim.biz.id/api/auth/me
200 OK
{
  "id": 2,
  "username": "hbingley1",
  "email": "hbingley1@plala.or.jp",
  "firstName": "Hugh",
  "lastName": "Bingley",
  "image": "https://robohash.org/Hugh.png"
}

Refresh token

Get a new access token using a refresh token.
fetch('https://axomock.fauzantaslim.biz.id/api/auth/refresh', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    refreshToken: 'a1b2c3d4e5f6...'
  })
})
.then(res => res.json())
.then(console.log);
axios.post('https://axomock.fauzantaslim.biz.id/api/auth/refresh', {
  refreshToken: 'a1b2c3d4e5f6...'
})
.then(res => console.log(res.data));
curl -X POST https://axomock.fauzantaslim.biz.id/api/auth/refresh \
-H "Content-Type: application/json" \
-d '{"refreshToken":"a1b2c3d4e5f6..."}'
200 OK
{
  "token": "eyJhbGciOiJIUzI1NiIsInR...",
  "refreshToken": "a1b2c3d4e5f6..."
}