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
This commit is contained in:
Lorenzo Blasa
2023-06-05 05:26:10 -07:00
committed by Facebook GitHub Bot
parent 353e51e2ea
commit 90240f4186

View File

@@ -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<string> => {
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();
};