get-token.ts•853 B
import { google } from "googleapis";
import readline from "readline";
import dotenv from "dotenv";
dotenv.config();
const { GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_REDIRECT_URI } =
process.env;
const oAuth2Client = new google.auth.OAuth2(
GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET,
GOOGLE_REDIRECT_URI
);
const SCOPES = ["https://www.googleapis.com/auth/calendar"];
const authUrl = oAuth2Client.generateAuthUrl({
access_type: "offline",
scope: SCOPES,
});
console.log("Authorize this app by visiting this URL:\n", authUrl);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question("\nEnter the code from that page here: ", async (code) => {
rl.close();
const { tokens } = await oAuth2Client.getToken(code);
console.log("\nYour refresh token is:\n", tokens.refresh_token);
});