Use auth token when connecting to existing server from Electron

Summary:
All clients need to provide an authentication token before connecting. Electron app is no different.

This change adds the authentication token whether we are connecting over UDS or TCP.

Before this change, if Flipper server was already running, launching the Electron app would look similar to this:

{F1016961594}

Reviewed By: antonk52

Differential Revision: D46418758

fbshipit-source-id: f00ffe675df78403d5921250e3e9ed9331a55bde
This commit is contained in:
Lorenzo Blasa
2023-06-05 05:26:10 -07:00
committed by Facebook GitHub Bot
parent 90240f4186
commit 98f376ec69
3 changed files with 75 additions and 47 deletions

View File

@@ -22,4 +22,4 @@ export {isFBBuild} from './fb-stubs/constants';
export {WEBSOCKET_MAX_MESSAGE_SIZE} from './comms/ServerWebSocket';
export {getAuthToken} from './utils/certificateUtils';
export {getAuthToken, hasAuthToken} from './utils/certificateUtils';

View File

@@ -266,10 +266,6 @@ const writeToTempFile = async (content: string): Promise<string> => {
return path;
};
const tokenFilename = 'auth.token';
const getTokenPath = (config: FlipperServerConfig): string => {
return getFilePath(tokenFilename);
};
const manifestFilename = 'manifest.json';
const getManifestPath = (config: FlipperServerConfig): string => {
return path.resolve(config.paths.staticPath, manifestFilename);
@@ -315,8 +311,8 @@ export const generateAuthToken = async () => {
return token;
};
export const getAuthToken = async () => {
if (!(await fs.pathExists(serverAuthToken))) {
export const getAuthToken = async (): Promise<string> => {
if (!(await hasAuthToken())) {
return generateAuthToken();
}
@@ -324,6 +320,10 @@ export const getAuthToken = async () => {
return token.toString();
};
export const hasAuthToken = async (): Promise<boolean> => {
return fs.pathExists(serverAuthToken);
};
export const validateAuthToken = (token: string) => {
if (!serverConfig) {
throw new Error(