Dashboard-Automatizase/docs/qa/google-oauth-redirect-uris.md
Luis Erlacher 0152a2fda0 feat: add n8n API testing script for Google OAuth2 schema and existing credentials
- Implemented a bash script to test n8n API and retrieve credential schemas.
- Added types for API responses, Google Calendar, and WhatsApp instances.
- Configured Vitest for testing with React and added setup for testing-library.
2025-10-10 14:29:02 -03:00

2.3 KiB

Configuração de Redirect URIs - Google OAuth

URLs para adicionar no Google Cloud Console

Ao configurar OAuth2 no Google Cloud Console (Credentials > OAuth 2.0 Client ID), adicione estas URIs:

Para Desenvolvimento (localhost)

http://localhost:3000/api/google-calendar/callback
https://n8n.automatizase.com.br/rest/oauth2-credential/callback

Para Produção

https://dashboard.automatizase.com.br/api/google-calendar/callback
https://n8n.automatizase.com.br/rest/oauth2-credential/callback

Por que duas URIs?

  1. /api/google-calendar/callback - Intercepta o callback do Google

    • Salva status no Supabase
    • Redireciona para n8n
  2. /rest/oauth2-credential/callback - Endpoint do n8n

    • Processa OAuth (troca code por tokens)
    • Salva credencial

Fluxo

Google → http://localhost:3000/api/google-calendar/callback
       ↓
Dashboard salva no banco
       ↓
Redirect → https://n8n.automatizase.com.br/rest/oauth2-credential/callback
       ↓
n8n processa OAuth e salva tokens

Passo a Passo no Google Cloud Console

  1. Acesse Google Cloud Console
  2. Selecione seu projeto
  3. Menu lateral → APIs & ServicesCredentials
  4. Clique na credencial OAuth 2.0 existente (ou crie uma nova)
  5. Em Authorized redirect URIs, clique em + ADD URI
  6. Adicione as 4 URIs acima (2 para dev, 2 para prod)
  7. Clique em SAVE

Verificação

Para testar se está configurado corretamente:

# Dev
curl "http://localhost:3000/api/google-calendar/callback?code=test&state=test"

# Deve redirecionar para:
# https://n8n.automatizase.com.br/rest/oauth2-credential/callback?code=test&state=test

Troubleshooting

Erro: redirect_uri_mismatch

Causa: A URI não está cadastrada no Google Cloud Console

Solução: Verifique se adicionou EXATAMENTE as URIs (inclusive o http vs https)

Erro: localhost não funciona

Causa: Google rejeita HTTP em produção, mas aceita para localhost

Solução: Use http://localhost:3000 (não HTTPS) para desenvolvimento local

Erro: URI com porta diferente

Se estiver rodando em porta diferente (ex: 3001), altere:

http://localhost:3001/api/google-calendar/callback

E atualize no Google Cloud Console.