2024-08-22 00:04:39 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
import { ipcMain } from "electron";
|
2024-09-18 21:06:34 +02:00
|
|
|
import { getWebServerEndpoint, getWSServerEndpoint } from "../frontend/util/endpoints";
|
2024-08-22 00:04:39 +02:00
|
|
|
|
|
|
|
const AuthKeyHeader = "X-AuthKey";
|
2024-10-27 21:12:41 +01:00
|
|
|
export const WaveAuthKeyEnv = "WAVETERM_AUTH_KEY";
|
2024-08-22 00:04:39 +02:00
|
|
|
export const AuthKey = crypto.randomUUID();
|
|
|
|
|
|
|
|
ipcMain.on("get-auth-key", (event) => {
|
|
|
|
event.returnValue = AuthKey;
|
|
|
|
});
|
|
|
|
|
|
|
|
export function configureAuthKeyRequestInjection(session: Electron.Session) {
|
|
|
|
const filter: Electron.WebRequestFilter = {
|
|
|
|
urls: [`${getWebServerEndpoint()}/*`, `${getWSServerEndpoint()}/*`],
|
|
|
|
};
|
|
|
|
session.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
|
|
|
|
details.requestHeaders[AuthKeyHeader] = AuthKey;
|
|
|
|
callback({ requestHeaders: details.requestHeaders });
|
|
|
|
});
|
|
|
|
}
|