UNPKG

gmail-to-exchange365

Version:

Complete Gmail to Exchange 365 migration tool with UI - Migrate emails, attachments, and folders seamlessly

38 lines (31 loc) 962 B
import { google } from "googleapis"; export function getGoogleOAuthClient() { return new google.auth.OAuth2( process.env.GOOGLE_CLIENT_ID!, process.env.GOOGLE_CLIENT_SECRET!, process.env.GOOGLE_REDIRECT! ); } export function generateGoogleAuthUrl() { const oauth = getGoogleOAuthClient(); return oauth.generateAuthUrl({ access_type: "offline", prompt: "consent", scope: [ "https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/gmail.labels", "email", "profile" ] }); } export async function exchangeGoogleCode(code: string) { const oauth = getGoogleOAuthClient(); const { tokens } = await oauth.getToken(code); return tokens; } export function refreshGoogleToken(refreshToken: string) { const oauth = getGoogleOAuthClient(); oauth.setCredentials({ refresh_token: refreshToken }); return oauth.refreshAccessToken(); }