-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_google_oauth.html
More file actions
397 lines (344 loc) · 13.3 KB
/
debug_google_oauth.html
File metadata and controls
397 lines (344 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🔧 Debug Google OAuth - Omega</title>
<script src="https://accounts.google.com/gsi/client" async defer></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
background: white;
border-radius: 20px;
padding: 30px;
max-width: 800px;
margin: 0 auto;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}
.header {
text-align: center;
margin-bottom: 30px;
}
.logo {
font-size: 2.5em;
font-weight: bold;
color: #333;
margin-bottom: 10px;
}
.subtitle {
color: #666;
font-size: 1.1em;
}
.debug-section {
background: #f8f9fa;
border: 2px solid #e9ecef;
border-radius: 10px;
padding: 20px;
margin: 20px 0;
}
.debug-title {
font-size: 1.2em;
font-weight: bold;
color: #333;
margin-bottom: 15px;
}
.info-grid {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 10px;
margin-bottom: 15px;
}
.info-label {
font-weight: bold;
color: #555;
}
.info-value {
color: #333;
font-family: monospace;
background: #fff;
padding: 5px;
border-radius: 4px;
word-break: break-all;
}
.btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 12px 24px;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
margin: 10px 5px;
transition: transform 0.2s;
}
.btn:hover {
transform: translateY(-2px);
}
.btn-test {
background: #28a745;
}
.status {
padding: 15px;
border-radius: 8px;
margin: 15px 0;
font-weight: bold;
}
.status.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.status.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.status.info {
background: #d1ecf1;
color: #0c5460;
border: 1px solid #b6d4d9;
}
.google-auth-section {
text-align: center;
padding: 20px;
background: #fff;
border-radius: 10px;
margin: 20px 0;
border: 2px solid #4285f4;
}
.steps {
text-align: left;
background: #e7f3ff;
padding: 20px;
border-radius: 10px;
border-left: 4px solid #2196f3;
}
.step {
margin: 10px 0;
padding: 10px;
background: white;
border-radius: 5px;
}
pre {
background: #f8f9fa;
padding: 10px;
border-radius: 5px;
overflow-x: auto;
margin: 10px 0;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<div class="logo">🔧 Debug Google OAuth</div>
<div class="subtitle">Herramienta de Diagnóstico para Omega API</div>
</div>
<!-- Información de Configuración -->
<div class="debug-section">
<div class="debug-title">📋 Información de Configuración</div>
<div class="info-grid">
<div class="info-label">Client ID:</div>
<div class="info-value">102613720703-cq73g92su0v8kevc0iuftjak0tm1e1al.apps.googleusercontent.com</div>
<div class="info-label">Dominio Actual:</div>
<div class="info-value" id="currentDomain">-</div>
<div class="info-label">URL Completa:</div>
<div class="info-value" id="currentUrl">-</div>
<div class="info-label">Estado de Google API:</div>
<div class="info-value" id="googleApiStatus">Cargando...</div>
<div class="info-label">Estado del Servidor:</div>
<div class="info-value" id="serverStatus">Verificando...</div>
</div>
</div>
<!-- Pasos para Solucionar -->
<div class="steps">
<h3>🛠️ Pasos para Solucionar el Error 400</h3>
<div class="step">
<strong>1. Verificar Dominio Autorizado en Google Console:</strong>
<br>• Ve a <a href="https://console.cloud.google.com/apis/credentials" target="_blank">Google Cloud Console</a>
<br>• Busca tu Client ID y haz clic en editar
<br>• En "Orígenes autorizados de JavaScript" agrega:
<pre>http://localhost:3000
http://127.0.0.1:3000
file://</pre>
</div>
<div class="step">
<strong>2. Verificar Configuración del Proyecto:</strong>
<br>• Asegúrate de que "Google+ API" esté habilitada
<br>• Verifica que el proyecto esté en estado "En producción" o "Prueba"
</div>
<div class="step">
<strong>3. Probar desde Servidor HTTP:</strong>
<br>• No uses file:// directamente, usa un servidor HTTP
<br>• Puedes usar: <code>python -m http.server 3000</code>
<br>• O instalar: <code>npm install -g http-server && http-server -p 3000</code>
</div>
</div>
<!-- Pruebas -->
<div class="debug-section">
<div class="debug-title">🧪 Pruebas de Conectividad</div>
<button class="btn btn-test" onclick="testServerConnection()">Probar Conexión con Servidor</button>
<button class="btn btn-test" onclick="testGoogleConfig()">Verificar Configuración Google</button>
<button class="btn btn-test" onclick="testManualToken()">Probar con Token Manual</button>
</div>
<!-- Sección de Google Auth -->
<div class="google-auth-section">
<div class="debug-title">🔐 Prueba de Google Sign-In</div>
<p style="margin-bottom: 20px;">Si aparece el botón de Google, la configuración básica es correcta:</p>
<div id="g_id_onload"
data-client_id="102613720703-cq73g92su0v8kevc0iuftjak0tm1e1al.apps.googleusercontent.com"
data-context="signin"
data-ux_mode="popup"
data-callback="handleCredentialResponse"
data-auto_prompt="false"
data-error_callback="handleGoogleError">
</div>
<div class="g_id_signin"
data-type="standard"
data-shape="rectangular"
data-theme="outline"
data-text="signin_with"
data-size="large"
data-logo_alignment="left">
</div>
</div>
<!-- Estado -->
<div id="status"></div>
<!-- Resultados -->
<div id="results"></div>
</div>
<script>
const API_BASE_URL = 'http://localhost:4000';
// Mostrar información inicial
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('currentDomain').textContent = window.location.hostname;
document.getElementById('currentUrl').textContent = window.location.href;
// Verificar si Google API se cargó
setTimeout(() => {
const status = window.google ? 'Cargado ✅' : 'Error ❌';
document.getElementById('googleApiStatus').textContent = status;
}, 2000);
// Verificar servidor
testServerConnection();
});
// Callback para respuesta exitosa de Google
function handleCredentialResponse(response) {
console.log('✅ Token recibido de Google:', response.credential);
showStatus('✅ Token de Google obtenido exitosamente!', 'success');
// Mostrar información del token
showResults(`
<h3>🎉 ¡Token de Google Obtenido!</h3>
<p><strong>Token ID:</strong> ${response.credential.substring(0, 50)}...</p>
<p><strong>Longitud:</strong> ${response.credential.length} caracteres</p>
<button class="btn" onclick="sendToAPI('${response.credential}')">Enviar a API de Omega</button>
`);
}
// Callback para errores de Google
function handleGoogleError(error) {
console.error('❌ Error de Google:', error);
showStatus(`❌ Error de Google: ${JSON.stringify(error)}`, 'error');
showResults(`
<h3>❌ Error de Google OAuth</h3>
<pre>${JSON.stringify(error, null, 2)}</pre>
<p><strong>Soluciones comunes:</strong></p>
<ul>
<li>Verificar que el dominio esté autorizado en Google Console</li>
<li>Usar un servidor HTTP en lugar de file://</li>
<li>Verificar que el Client ID sea correcto</li>
<li>Asegurar que Google+ API esté habilitada</li>
</ul>
`);
}
// Enviar token a la API
async function sendToAPI(token) {
try {
showStatus('🔄 Enviando token a la API...', 'info');
const response = await fetch(`${API_BASE_URL}/usuarios/auth/google`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
googleToken: token
})
});
const data = await response.json();
if (response.ok) {
showStatus('✅ ¡Autenticación exitosa!', 'success');
showResults(`
<h3>🎉 ¡Autenticación Exitosa!</h3>
<pre>${JSON.stringify(data, null, 2)}</pre>
`);
} else {
showStatus(`❌ Error de la API: ${data.message}`, 'error');
showResults(`
<h3>❌ Error de la API</h3>
<pre>${JSON.stringify(data, null, 2)}</pre>
`);
}
} catch (error) {
showStatus(`❌ Error de conexión: ${error.message}`, 'error');
}
}
// Probar conexión con servidor
async function testServerConnection() {
try {
const response = await fetch(`${API_BASE_URL}/ping`);
const data = await response.json();
document.getElementById('serverStatus').textContent = 'Conectado ✅';
showStatus('✅ Servidor conectado correctamente', 'success');
} catch (error) {
document.getElementById('serverStatus').textContent = 'Error ❌';
showStatus('❌ Error de conexión con el servidor. ¿Está ejecutándose?', 'error');
}
}
// Verificar configuración de Google
function testGoogleConfig() {
const hasGoogle = !!window.google;
const hasGsi = !!window.google?.accounts?.id;
showResults(`
<h3>🔍 Estado de Google API</h3>
<ul>
<li>Google API cargada: ${hasGoogle ? '✅' : '❌'}</li>
<li>Google Sign-In disponible: ${hasGsi ? '✅' : '❌'}</li>
<li>Dominio actual: ${window.location.hostname}</li>
<li>Protocolo: ${window.location.protocol}</li>
</ul>
<p><strong>Recomendaciones:</strong></p>
<ul>
<li>Si usas file://, cambia a http://localhost</li>
<li>Verifica dominios autorizados en Google Console</li>
</ul>
`);
}
// Probar con token manual
function testManualToken() {
const token = prompt('Ingresa un token de Google para probar:');
if (token) {
sendToAPI(token);
}
}
// Mostrar estado
function showStatus(message, type) {
const statusDiv = document.getElementById('status');
statusDiv.className = `status ${type}`;
statusDiv.textContent = message;
}
// Mostrar resultados
function showResults(html) {
const resultsDiv = document.getElementById('results');
resultsDiv.innerHTML = `<div class="debug-section">${html}</div>`;
}
</script>
</body>
</html>