POST
https://api.myidvirtual.com
/
auth
/
otp
/
verify
Verificar OTP
curl --request POST \
  --url https://api.myidvirtual.com/auth/otp/verify \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "token": "<string>"
}
'
{
  "valid": true,
  "message": "Código OTP verificado com sucesso",
  "timestamp": "2024-01-15T10:30:00.000Z"
}

Verificar OTP

Endpoint para verificar códigos OTP gerados por aplicativos autenticadores, usado tanto para login quanto para validação de operações sensíveis.

Autenticação

Authorization
string
required
Bearer token JWT do usuário autenticado

Parâmetros

Request Body

token
string
required
Código OTP de 6 dígitos gerado pelo app autenticador

Responses

{
  "valid": true,
  "message": "Código OTP verificado com sucesso",
  "timestamp": "2024-01-15T10:30:00.000Z"
}

Exemplo de Requisição

curl --location --request POST 'http://localhost:3333/auth/otp/verify' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' \
--header 'Content-Type: application/json' \
--data-raw '{
  "token": "123456"
}'

Casos de Uso

1. Login com 2FA

const loginWith2FA = async (email, password) => {
  // 1. Login normal
  const loginResponse = await fetch('/auth/signin', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ email, password })
  });

  if (loginResponse.status === 200) {
    const { access_token, requires2FA } = await loginResponse.json();

    if (requires2FA) {
      // 2. Solicitar OTP
      const otpCode = await showOTPModal();

      // 3. Verificar OTP
      const otpResponse = await fetch('/auth/otp/verify', {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${access_token}`,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ token: otpCode })
      });

      if (otpResponse.ok) {
        // Login completo
        localStorage.setItem('access_token', access_token);
        window.location.href = '/dashboard';
      }
    } else {
      // Login sem 2FA
      localStorage.setItem('access_token', access_token);
      window.location.href = '/dashboard';
    }
  }
};

Troubleshooting

Problemas Comuns

ProblemaCausaSolução
Código sempre inválidoRelógio dessinronizadoSincronizar tempo do dispositivo
”OTP não configurado”2FA não ativadoAtivar 2FA primeiro
Código não aceitoInserido muito tardeUsar próximo código
Códigos OTP são válidos por apenas 30 segundos. Certifique-se de usar o código atual do aplicativo.
Implemente interface que mostre o tempo restante para o código atual expirar.

Próximos Passos

  1. Configure rate limiting adequado
  2. Implemente códigos de backup como alternativa
  3. Configure logs de auditoria detalhados
  4. Teste sincronização de tempo