# Instalar auth en local - Instalar auth 1. git clone https://github.com/alliende/auth.git 2. Bajar la imagen de la BD 3. npm i 4. npm run createContainerDB 5. npm run initDB 6. npm start - Instalar ngrok y establecer la conexión entre ngrok y el servicio auth 1. [descargar ngrok](ngrok.com) para darle acceso a google al servicio auth local 2. `./ngrok http 3001` Conectar ngrok con auth (puerto definido en auth) 3. Utilizar el tunel creado para reemplazarlo en los archivos (https://XXX.ngrok.io) - Crear una nueva aplicación con google para utilizar la api de google calendar 1. Crear un nuevo proyecto 2. Habilitar la API de Google Calendar en sección Agregar APIs. Botón `+ habilitar apis y servicios`, dentro de panel de control, encontrar google calendar api y hacer click en habilitar. 3. Sección de Credenciales del proyecto: 1. Crear Credenciales > Help me choose (seguir instrucciones del repositorio) - Responder preguntas, - Ingresar URIs de origenes de javascript autorizados - https://XXX.ngrok.io - Ingresar URI de redireccuón autorizados - https://XXX.ngrok.io/choose-calendar - https://XXX.ngrok.io/choose-calendar/google 2. Configurar pantalla de consentimiento - Definir Dominios autorizados - https://XXX.ngrok.io 3. Verificación del dominio - Ingresar la uri https://XXX.ngrok.io - Descargar archivo .html - Copiar el google-site-verification en routes.js en la primera ruta - Hacer click en verificar - Volver a ingresar la uri verificada en verificación del dominio - Cambios en auth_app - .env: ``` REACT_APP_AUTH_URL a: https://XXX.ngrok.io ``` - src/components/ChooseCalendar/index.js: ``` ... const onSave = async calendarId => { try { setLoading(true) setCalendars(null) const { data: { ok, error: setCalendarError } } = await post( `${process.env.REACT_APP_AUTH_URL}/set-${service}-calendar`, { calendarId, userId } ) if (ok) { window.open(`http://${hostname}`, '_self') // Línea a eliminar window.open(`http://localhost:3000`, '_self') // Línea a agregar } else { setError(setCalendarError) } } catch (e) { console.log(e) setError(e) } setLoading(false) } ... ``` - npm run build - Copiar carpeta build a www en auth - Cambios en auth - .env: ``` AUTH_URL=https://XXX.ngrok.io GOOGLE_CLIENT_ID=XXX GOOGLE_CLIENT_SECRET=XXX ``` - package.json ``` "createContainerDB": "docker run -p 8080:8080 -p 28016:28015 -d --name auth -v `pwd`/db/data/loadDB:/loadDB -v `pwd`/db/data/saveDB:/saveDB db_dev:1", ``` - src/crons/index.js ``` export default function runCrons(queries) { // sundayCron(async logger => renewGoogleSubscription(queries, logger)) // oddCron(async logger => renewOutlookSubscription(queries, logger)) } ``` - src/handlers.js ``` ln: 101 const { ok, error } = await request( `$http://${hostname}/api/google-login-success`, null, { method: 'POST', body: { userId }, jsonResponse: true } ) ``` ``` ln: 410 const { ok, error, failedEvents } = await request( `http://${hostname}/api/events/${user.id}`, null, { method: 'POST', body: { events, service: 'google' }, jsonResponse: true } ) ``` ``` ln: 560 const { ok, error, failedEvents } = await request( `http://${hostname}/api/service-calendar-success`, null, { method: 'POST', body: { userId, events, service: 'google' }, jsonResponse: true } ) ``` ``` ln: 630 /* If user doesn't exists, create it */ if (!user) { await queries.insertUser({ hostname: 'localhost:2707', id: userId }) } ``` ``` ln: 740 const { ok, error } = await request( `http://${hostname}/api/outlook-login-success`, null, { method: 'POST', body: { userId }, jsonResponse: true } ) ``` ``` ln: 880 const { ok, error, failedEvents } = await request( `http://${hostname}/api/service-calendar-success`, null, { method: 'POST', body: { userId, events, service: 'outlook' }, jsonResponse: true } ) ``` ``` ln: 1230 const { ok, error, failedEvents } = await request( `http://${hostname}/api/events/${userId}`, null, { method: 'POST', body: { events, service: 'outlook' }, jsonResponse: true } ) ``` - src/routes.js ``` app.get('/googleXXX.html', (req, res) => { res.send('google-site-verification: googleXXX.html') }) ``` - src/utils.js ``` ln: 85 /* Get Date from hostname, so we update agenda at the date they actually are */ let shortDate try { shortDate = (await exports.request(`http://${hostname}/api/getDate`, null, { jsonResponse: true })).date } catch (e) { shortDate = null } ``` ``` ln: 262 /* Get Date from hostname, so we update agenda at the date they actually are */ const { date: shortDate } = await exports.request( `http://${hostname}/api/getDate`, null, { jsonResponse: true } ) ``` - Cambios en equip_api - actionReducer ``` // Dentro de la acción GOOGLE_LOGOUT const response = await request('https://XXX.ngrok.io/google-logout', null, { method: 'POST', body: { userId }, jsonResponse: true }) ``` - Cambios en equip_web - domains/agenda/components/AppBar/ProfileMenu/index.js ``` ln: 65 /** * @description Open a url to login in google */ openGoogleLogin = () => { const { userId } = this.props const [, , domain] = window.location.href.split('/') window.open( `https://XXX.ngrok.io/google-auth?host=${domain}&userId=${userId}`, '_self' ) } ``` ``` ln: 77 /** * @description Open a url to login in outlokk */ openOutlookLogin = () => { const { userId } = this.props const [, , domain] = window.location.href.split('/') window.open( `https://XXX.ngrok.iooutlook-auth?host=${domain}&userId=${userId}`, '_self' ) } ```