From 7f5a5839ec12376b1cb6312ddab3f975d070d12e Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 15 Sep 2024 18:44:27 +0530 Subject: [PATCH] feat: intialize google oauth flow --- server/src/routes/auth.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 74a33d93..b3c2d9a3 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -1,6 +1,24 @@ -import { Router } from 'express'; -export const router = Router(); +import { Router } from 'express';; +import { google } from "googleapis"; +import { OAuth2Client } from 'google-auth-library' -router.post('/auth/google', (req, res) => { - res.send('Google auth'); +export const router = Router() + +const oauth2Client = new OAuth2Client( + '_CLIENT_ID', + '_CLIENT_SECRET', + '_REDIRECT_URI' +); + +// initialize Google OAuth 2.0 flow +router.get('/auth/google', (req, res) => { + const url = oauth2Client.generateAuthUrl({ + access_type: 'offline', + scope: [ + 'https://www.googleapis.com/auth/userinfo.profile', + 'https://www.googleapis.com/auth/drive.file', + 'https://www.googleapis.com/auth/spreadsheets' + ] + }); + res.redirect(url); }); \ No newline at end of file