From f6de499171cc511d26767c905de0dd3ed081a356 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Wed, 18 Oct 2023 12:28:06 -0700 Subject: [PATCH] Export to manifest on get Summary: Every time the token is returned, export it to the manifest. This covers the case in which the token found in the manifest has already expired. Reviewed By: antonk52 Differential Revision: D50419458 fbshipit-source-id: 8eefa0e97e234985b34f824190b208bf74e2d8ec --- .../certificate-exchange/certificate-utils.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/desktop/flipper-server-core/src/app-connectivity/certificate-exchange/certificate-utils.tsx b/desktop/flipper-server-core/src/app-connectivity/certificate-exchange/certificate-utils.tsx index ba7f9e3269e..04440351965 100644 --- a/desktop/flipper-server-core/src/app-connectivity/certificate-exchange/certificate-utils.tsx +++ b/desktop/flipper-server-core/src/app-connectivity/certificate-exchange/certificate-utils.tsx @@ -332,6 +332,18 @@ export const generateAuthToken = async () => { return token; }; +/** + * Gets the client authentication token. If there is no existing token, + * it generates one, export it to the manifest file and returns it. + * + * Additionally, it must check the token's validity before returning it. + * If the token is invalid, it regenerates it and exports it to the manifest file. + * + * Finally, the token is also exported to the manifest, on every get as to + * ensure it is always up to date. + * + * @returns + */ export const getAuthToken = async (): Promise => { if (!(await hasAuthToken())) { return generateAuthToken(); @@ -349,6 +361,12 @@ export const getAuthToken = async (): Promise => { return generateAuthToken(); } + const config = getFlipperServerConfig(); + if (config.environmentInfo.isHeadlessBuild) { + console.info('Token exported to manifest'); + await exportTokenToManifest(config, token.toString()); + } + return token.toString(); };