Phase 1.1: Generate authentication token in RuntimeController

- Add authenticationToken field to store GUID

- Generate secure token using Guid.NewGuid().ToString('N')

- Pass token to Electron via --authtoken command-line parameter

- Token is 32 hex characters with 128 bits of entropy
This commit is contained in:
Pierre Arnaud
2026-01-30 19:13:12 +01:00
parent 6847520ea8
commit f598fbf5ce
2 changed files with 5 additions and 2 deletions

View File

@@ -31,6 +31,7 @@ namespace ElectronNET.AspNet.Runtime
private int? port;
private string actualUrl;
private bool electronLaunched;
private string authenticationToken;
public RuntimeControllerAspNetDotnetFirstSignalR(
AspNetLifetimeAdapter aspNetLifetimeAdapter,
@@ -108,9 +109,12 @@ namespace ElectronNET.AspNet.Runtime
private void LaunchElectron()
{
// Generate secure authentication token
this.authenticationToken = Guid.NewGuid().ToString("N"); // 32 hex chars, no hyphens
var isUnPacked = ElectronNetRuntime.StartupMethod.IsUnpackaged();
var flag = isUnPacked ? "--unpackeddotnetsignalr" : "--dotnetpackedsignalr";
var args = $"{flag} --electronurl={this.actualUrl}";
var args = $"{flag} --electronurl={this.actualUrl} --authtoken={this.authenticationToken}";
this.electronProcess = new ElectronProcessActive(isUnPacked, ElectronNetRuntime.ElectronExecutable, args, this.port.Value);
// Note: We do NOT subscribe to electronProcess.Ready in SignalR mode.

View File

@@ -1,6 +1,5 @@
using ElectronNET.API;
using ElectronNET.API.Entities;
using ElectronNET.Samples.BlazorSignalR.Components;
var builder = WebApplication.CreateBuilder(args);