From 90240f4186faafef64381ac7071a2ae8a9ced1d5 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Mon, 5 Jun 2023 05:26:10 -0700 Subject: [PATCH] Move auth token to the default directory for crypto related files Summary: Used to be stored in the static directory as it was meant to be used by connecting clients. This is still the case, except that there may be different clients with different static directories all trying to connect to the same server. Instead, store the authentication token with the other crypto files, in the user's home directory. By doing this, all clients, as long as they have access to the local filesystem, can use it. Reviewed By: mweststrate Differential Revision: D46418639 fbshipit-source-id: 181e98346d86ad7b3fc1d0005aca3350deb6df32 --- .../src/utils/certificateUtils.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/desktop/flipper-server-core/src/utils/certificateUtils.tsx b/desktop/flipper-server-core/src/utils/certificateUtils.tsx index cf4b70b1d..d6ba92c74 100644 --- a/desktop/flipper-server-core/src/utils/certificateUtils.tsx +++ b/desktop/flipper-server-core/src/utils/certificateUtils.tsx @@ -37,6 +37,7 @@ export const serverKey = getFilePath('server.key'); export const serverCsr = getFilePath('server.csr'); export const serverSrl = getFilePath('server.srl'); export const serverCert = getFilePath('server.crt'); +export const serverAuthToken = getFilePath('auth.token'); // Device file paths export const csrFileName = 'app.csr'; @@ -267,10 +268,6 @@ const writeToTempFile = async (content: string): Promise => { const tokenFilename = 'auth.token'; const getTokenPath = (config: FlipperServerConfig): string => { - if (config.environmentInfo.isHeadlessBuild) { - return path.resolve(config.paths.staticPath, tokenFilename); - } - return getFilePath(tokenFilename); }; const manifestFilename = 'manifest.json'; @@ -309,7 +306,7 @@ export const generateAuthToken = async () => { expiresIn: '21 days', }); - await fs.writeFile(getTokenPath(config), token); + await fs.writeFile(serverAuthToken, token); if (config.environmentInfo.isHeadlessBuild) { await exportTokenToManifest(config, token); @@ -319,14 +316,11 @@ export const generateAuthToken = async () => { }; export const getAuthToken = async () => { - const config = getFlipperServerConfig(); - const tokenPath = getTokenPath(config); - - if (!(await fs.pathExists(tokenPath))) { + if (!(await fs.pathExists(serverAuthToken))) { return generateAuthToken(); } - const token = await fs.readFile(tokenPath); + const token = await fs.readFile(serverAuthToken); return token.toString(); };