Autenticação - API Lojaz Delivery
POST
-
Obter token
Antes de realizar qualquer ação, é necessário gerar um token. Você pode fazer isso utilizando esta rota.
PATH
Headers
Exemplo em NodeJS:
const axios = require('axios');
const getToken = async () => {
try {
const { data } = await axios.post("BASE_URL/auth/token", {
headers: {
Authorization: `Basic ${Buffer.from("email:password").toString("base64")}`
}
});
// data contains response 200 model
} catch (error) {
// unauthorized
}
};
module.exports = getToken;
O Token dura aproximadamente 10 minutos até ser expirado, é necessário gerar outro com o refresh_token, veja o exemplo abaixo
Response - OK (200)
{ "status": true, "data": { "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI...", "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6I...", "expiresIn": 1724621531288, "expiresInDate": "2024-08-25T21:32:11.288Z" } }
Content-Type: application/json
Response - Unauthorized (401)
{ "status": true, "message": "Unauthorized" }
Content-Type: application/json
POST
-
Obter Refresh token
Para recarregar um token expirado
PATH
Body
{ "refresh_token": "refresh token" }
Content-Type: application/json
Exemplo em NodeJS:
const axios = require('axios');
const refreshToken = async () => {
try {
const response = await axios.post('BASE_URL/auth/refresh', {
refresh_token: "REFRESH_TOKEN"
}, {
headers: {
'Content-Type': 'application/json'
}
});
// handle response
} catch (error) {
// handle error
}
};
module.exports = refreshToken;
O Refresh token dura um dia até ser expirado
O Refresh token só pode ser usado 1 vez na rota de recarregar, após isso um novo refresh token é gerado
Response - OK (200)
{ "status": true, "data": { "access_token": "novo token", "refresh_token": "novo refresh token", "expiresIn": 1724621531288, "expiresInDate": "2024-08-25T21:32:11.288Z" } }
Content-Type: application/json
Response - Unauthorized (401)
{ "status": true, "message": "Unauthorized" }
Content-Type: application/json