2024-09-15 18:44:27 +05:30
|
|
|
import { Router } from 'express';;
|
|
|
|
|
import { google } from "googleapis";
|
|
|
|
|
import { OAuth2Client } from 'google-auth-library'
|
2024-09-15 17:54:11 +05:30
|
|
|
|
2024-09-15 18:44:27 +05:30
|
|
|
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);
|
2024-09-15 17:54:38 +05:30
|
|
|
});
|