mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 06:59:09 +00:00
check keys of client secrets
This commit is contained in:
@@ -455,8 +455,8 @@ export async function uploadGoogleSheetClientFile(req, res) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const client = JSON.parse(fs.readFileSync(req.file.path as string, 'utf-8'));
|
const client = JSON.parse(fs.readFileSync(req.file.path as string, 'utf-8'));
|
||||||
const auth = await Sheet.saveClientSecrets(client);
|
await Sheet.saveClientSecrets(client);
|
||||||
res.status(200).send(auth);
|
res.status(200).send('OK');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).send({ message: error.toString() });
|
res.status(500).send({ message: error.toString() });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,22 +38,25 @@ class sheet {
|
|||||||
if (!sheet.client) {
|
if (!sheet.client) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret.auth = await this.refreshToken();
|
try {
|
||||||
if (ret.auth) {
|
ret.auth = await this.refreshToken();
|
||||||
const settings = DataProvider.getGoogleSheet();
|
if (ret.auth) {
|
||||||
const x = await this.exist(settings.id, settings.worksheet);
|
const settings = DataProvider.getGoogleSheet();
|
||||||
if (x === true) {
|
const x = await this.exist(settings.id, settings.worksheet);
|
||||||
ret.id = true;
|
if (x === true) {
|
||||||
this.sheetId = settings.id;
|
ret.id = true;
|
||||||
} else if (x !== false) {
|
this.sheetId = settings.id;
|
||||||
ret.id = true;
|
} else if (x !== false) {
|
||||||
ret.worksheet = true;
|
ret.id = true;
|
||||||
this.sheetId = settings.id;
|
ret.worksheet = true;
|
||||||
this.worksheetId = x.worksheetId;
|
this.sheetId = settings.id;
|
||||||
this.range = x.range;
|
this.worksheetId = x.worksheetId;
|
||||||
|
this.range = x.range;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(LogOrigin.Server, `Google Sheet: Faild to refresh token ${err}`);
|
||||||
}
|
}
|
||||||
logger.info(LogOrigin.Server, `Sheet State: ${JSON.stringify(ret)}`);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,17 +202,24 @@ class sheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* saves Object to appdata path as client_secret.json
|
* saves Object to appdata path as client_secret.json
|
||||||
* @param {} secrets
|
* @param {Object} secrets
|
||||||
*/
|
*/
|
||||||
public async saveClientSecrets(secrets): Promise<GoogleSheetState> {
|
public async saveClientSecrets(secrets: Object) {
|
||||||
ensureDirectory(this.sheetsFolder);
|
|
||||||
logger.info(LogOrigin.Server, 'Sheets: got new client_secret');
|
|
||||||
//TODO: test that this is actualy a client file?
|
|
||||||
//invalidate previus auths
|
|
||||||
sheet.client = null;
|
sheet.client = null;
|
||||||
sheet.authUrl = null;
|
sheet.authUrl = null;
|
||||||
|
ensureDirectory(this.sheetsFolder);
|
||||||
|
if (
|
||||||
|
'client_id' in secrets ||
|
||||||
|
!('project_id' in secrets) ||
|
||||||
|
!('auth_uri' in secrets) ||
|
||||||
|
!('token_uri' in secrets) ||
|
||||||
|
!('auth_provider_x509_cert_url' in secrets) ||
|
||||||
|
!('client_secret' in secrets) ||
|
||||||
|
!('redirect_uris' in secrets)
|
||||||
|
) {
|
||||||
|
throw new Error('Sheet slient secret is missing some keys');
|
||||||
|
}
|
||||||
await writeFile(this.client_secret, JSON.stringify(secrets), 'utf-8');
|
await writeFile(this.client_secret, JSON.stringify(secrets), 'utf-8');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user