don't reuse oauth client (#32)

This commit is contained in:
Dustin Decker 2023-01-30 10:02:36 -08:00 committed by GitHub
parent 7cbd6b7cac
commit 2bb3556c1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

3
api.js
View file

@ -25,7 +25,6 @@ const {OAuth2Client} = require('google-auth-library');
const SCREENSHOTS_DIR = path.resolve(process.env.SCREENSHOTS_DIR);
const client = new OAuth2Client(process.env.CLIENT_ID, process.env.CLIENT_SECRET, process.env.NODE_ENV == 'production' ? `https://${process.env.HOSTNAME}/oauth-login` : `http://${process.env.HOSTNAME}/oauth-login`);
const SCREENSHOT_FILENAME_REGEX = new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\.png$/i);
@ -171,6 +170,7 @@ async function set_up_api_server(app) {
});
app.get('/login', (req, res) => {
const client = new OAuth2Client(process.env.CLIENT_ID, process.env.CLIENT_SECRET, process.env.NODE_ENV == 'production' ? `https://${process.env.HOSTNAME}/oauth-login` : `http://${process.env.HOSTNAME}/oauth-login`);
const authUrl = client.generateAuthUrl({
redirect_uri: process.env.NODE_ENV == 'production' ? `https://${process.env.HOSTNAME}/oauth-login` : `http://${process.env.HOSTNAME}/oauth-login`,
access_type: 'offline',
@ -181,6 +181,7 @@ async function set_up_api_server(app) {
});
app.get('/oauth-login', async (req, res) => {
const client = new OAuth2Client(process.env.CLIENT_ID, process.env.CLIENT_SECRET, process.env.NODE_ENV == 'production' ? `https://${process.env.HOSTNAME}/oauth-login` : `http://${process.env.HOSTNAME}/oauth-login`);
try{
const code = req.query.code;
const {tokens} = await client.getToken(code);