curl --request POST \
--url https://api.econpay.com.br/auth \
--header 'Content-Type: application/json' \
--data '{
"email": "[email protected]",
"password": "sua-senha"
}'
const response = await fetch('https://api.econpay.com.br/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: '[email protected]',
password: 'sua-senha'
})
});
const data = await response.json();
const token = data.response.token;
// Usar token em requisições futuras
const paymentResponse = await fetch('https://api.econpay.com.br/payments/order', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
// ...
});
import requests
response = requests.post(
'https://api.econpay.com.br/auth',
json={
'email': '[email protected]',
'password': 'sua-senha'
}
)
data = response.json()
token = data['response']['token']
# Usar token em requisições futuras
payment_response = requests.post(
'https://api.econpay.com.br/payments/order',
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
},
# ...
)
<?php
$ch = curl_init('https://api.econpay.com.br/auth');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'email' => '[email protected]',
'password' => 'sua-senha'
]));
$response = curl_exec($ch);
$data = json_decode($response, true);
$token = $data['response']['token'];
curl_close($ch);
// Usar token em requisições futuras
$ch = curl_init('https://api.econpay.com.br/payments/order');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
// ...
?>
{
"response": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjQwMTIzNDU2LCJleHAiOjE2NDAxMjcwNTZ9.abc123def456...",
"user": {
"id": 1,
"name": "João da Silva",
"email": "[email protected]",
"role": "admin"
}
}
}
{
"statusCode": 401,
"message": "Email ou senha inválidos"
}
Autenticação
POST /auth
Autenticar e obter token JWT
POST
/
auth
curl --request POST \
--url https://api.econpay.com.br/auth \
--header 'Content-Type: application/json' \
--data '{
"email": "[email protected]",
"password": "sua-senha"
}'
const response = await fetch('https://api.econpay.com.br/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: '[email protected]',
password: 'sua-senha'
})
});
const data = await response.json();
const token = data.response.token;
// Usar token em requisições futuras
const paymentResponse = await fetch('https://api.econpay.com.br/payments/order', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
// ...
});
import requests
response = requests.post(
'https://api.econpay.com.br/auth',
json={
'email': '[email protected]',
'password': 'sua-senha'
}
)
data = response.json()
token = data['response']['token']
# Usar token em requisições futuras
payment_response = requests.post(
'https://api.econpay.com.br/payments/order',
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
},
# ...
)
<?php
$ch = curl_init('https://api.econpay.com.br/auth');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'email' => '[email protected]',
'password' => 'sua-senha'
]));
$response = curl_exec($ch);
$data = json_decode($response, true);
$token = $data['response']['token'];
curl_close($ch);
// Usar token em requisições futuras
$ch = curl_init('https://api.econpay.com.br/payments/order');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
// ...
?>
{
"response": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjQwMTIzNDU2LCJleHAiOjE2NDAxMjcwNTZ9.abc123def456...",
"user": {
"id": 1,
"name": "João da Silva",
"email": "[email protected]",
"role": "admin"
}
}
}
{
"statusCode": 401,
"message": "Email ou senha inválidos"
}
Descrição
Endpoint para autenticação de usuários. Retorna um token JWT que deve ser usado no headerAuthorization de todas as requisições subsequentes.
O token JWT expira em 1 hora. Após expirar, você precisará fazer login novamente.
Request Body
string
required
Email do usuário cadastrado
string
required
Senha do usuário
Response
object
curl --request POST \
--url https://api.econpay.com.br/auth \
--header 'Content-Type: application/json' \
--data '{
"email": "[email protected]",
"password": "sua-senha"
}'
const response = await fetch('https://api.econpay.com.br/auth', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: '[email protected]',
password: 'sua-senha'
})
});
const data = await response.json();
const token = data.response.token;
// Usar token em requisições futuras
const paymentResponse = await fetch('https://api.econpay.com.br/payments/order', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
// ...
});
import requests
response = requests.post(
'https://api.econpay.com.br/auth',
json={
'email': '[email protected]',
'password': 'sua-senha'
}
)
data = response.json()
token = data['response']['token']
# Usar token em requisições futuras
payment_response = requests.post(
'https://api.econpay.com.br/payments/order',
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
},
# ...
)
<?php
$ch = curl_init('https://api.econpay.com.br/auth');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'email' => '[email protected]',
'password' => 'sua-senha'
]));
$response = curl_exec($ch);
$data = json_decode($response, true);
$token = $data['response']['token'];
curl_close($ch);
// Usar token em requisições futuras
$ch = curl_init('https://api.econpay.com.br/payments/order');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
// ...
?>
{
"response": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNjQwMTIzNDU2LCJleHAiOjE2NDAxMjcwNTZ9.abc123def456...",
"user": {
"id": 1,
"name": "João da Silva",
"email": "[email protected]",
"role": "admin"
}
}
}
{
"statusCode": 401,
"message": "Email ou senha inválidos"
}
Usando o Token
Após obter o token, inclua-o no headerAuthorization de todas as requisições:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Renovação de Token
O token expira em 1 hora. Implemente lógica para renovar automaticamente:let token = null;
let tokenExpiry = null;
async function getValidToken() {
// Se não tem token ou expirou, fazer login
if (!token || Date.now() > tokenExpiry) {
const response = await fetch('https://api.econpay.com.br/auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: process.env.EMAIL,
password: process.env.PASSWORD
})
});
const data = await response.json();
token = data.response.token;
tokenExpiry = Date.now() + (3600 * 1000); // 1 hora
}
return token;
}
// Usar em requisições
const validToken = await getValidToken();