mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-19 15:16:20 +00:00
Respect auth token from Node.js start
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
internal const int DefaultWebPort = 8001;
|
||||
internal const string ElectronPortArgumentName = "electronPort";
|
||||
internal const string ElectronPidArgumentName = "electronPID";
|
||||
internal const string ElectronAuthTokenArgumentName = "electronAuthToken";
|
||||
|
||||
/// <summary>Initializes the <see cref="ElectronNetRuntime"/> class.</summary>
|
||||
static ElectronNetRuntime()
|
||||
|
||||
@@ -75,10 +75,10 @@
|
||||
if (portArg != null)
|
||||
{
|
||||
var parts = portArg.Split('=', StringSplitOptions.TrimEntries);
|
||||
|
||||
if (parts.Length > 1 && int.TryParse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out var result))
|
||||
{
|
||||
ElectronNetRuntime.ElectronSocketPort = result;
|
||||
|
||||
Console.WriteLine("Use Electron Port: " + result);
|
||||
}
|
||||
}
|
||||
@@ -88,18 +88,33 @@
|
||||
if (pidArg != null)
|
||||
{
|
||||
var parts = pidArg.Split('=', StringSplitOptions.TrimEntries);
|
||||
|
||||
if (parts.Length > 1 && int.TryParse(parts[1], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out var result))
|
||||
{
|
||||
ElectronNetRuntime.ElectronProcessId = result;
|
||||
|
||||
Console.WriteLine("Electron Process ID: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
var authTokenArg = argsList.FirstOrDefault(e => e.Contains(ElectronNetRuntime.ElectronAuthTokenArgumentName, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (authTokenArg != null)
|
||||
{
|
||||
var parts = authTokenArg.Split('=', StringSplitOptions.TrimEntries);
|
||||
|
||||
if (parts.Length > 1 && !string.IsNullOrWhiteSpace(parts[1]))
|
||||
{
|
||||
var result = parts[1];
|
||||
ElectronNetRuntime.ElectronAuthToken = result;
|
||||
Console.WriteLine("Use Auth Token: " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetElectronExecutable()
|
||||
{
|
||||
string executable = ElectronNetRuntime.BuildInfo.ElectronExecutable;
|
||||
var executable = ElectronNetRuntime.BuildInfo.ElectronExecutable;
|
||||
|
||||
if (string.IsNullOrEmpty(executable))
|
||||
{
|
||||
throw new Exception("AssemblyMetadataAttribute 'ElectronExecutable' could not be found!");
|
||||
|
||||
@@ -3,6 +3,7 @@ const { BrowserWindow } = require('electron');
|
||||
const { createServer } = require('http');
|
||||
const { randomUUID } = require('crypto');
|
||||
const { Server } = require('socket.io');
|
||||
const { platform } = require('os');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const cProcess = require('child_process').spawn;
|
||||
@@ -395,13 +396,13 @@ function startAspCoreBackend(electronPort) {
|
||||
envParam,
|
||||
`/electronPort=${electronPort}`,
|
||||
`/electronPID=${process.pid}`,
|
||||
`/electronAuthToken=${authToken}`,
|
||||
// forward user supplied args (avoid duplicate environment)
|
||||
...forwardedArgs.filter(a => !(envParam && a.startsWith('--environment=')))
|
||||
].filter(p => p);
|
||||
let binaryFile = manifestJsonFile.executable;
|
||||
|
||||
const os = require('os');
|
||||
if (os.platform() === 'win32') {
|
||||
if (platform() === 'win32') {
|
||||
binaryFile = binaryFile + '.exe';
|
||||
}
|
||||
|
||||
@@ -430,8 +431,7 @@ function startAspCoreBackendUnpackaged(electronPort) {
|
||||
].filter(p => p);
|
||||
let binaryFile = manifestJsonFile.executable;
|
||||
|
||||
const os = require('os');
|
||||
if (os.platform() === 'win32') {
|
||||
if (platform() === 'win32') {
|
||||
binaryFile = binaryFile + '.exe';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user