Authentication through Azure AD (Microsoft EntraID) does not work #945

Closed
opened 2026-01-29 16:52:29 +00:00 by claunia · 4 comments
Owner

Originally created by @ThomasStarnes on GitHub (May 3, 2024).

  • Versions:

    • Electron.NET: 23.6.2
    • .NET: 7.0
    • Node.JS: 20.12.2
  • Target: Windows

I'm working on a Blazor Server app and have been tasked with creating a desktop version of the app. I have been trying to use Electron.NET, but I am running into issues when authenticating through Azure AD while using Electron.NET. I'm receiving the following error:

stdout: fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HN2V44AL6L5H", Request id "0HN2V44AL6L5H:00000002": An unhandled exception was thrown by the application. System.Exception: An error was encountered while handling the remote login. ---> System.Exception: Correlation failed. --- End of inner exception stack trace --- at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler1.HandleRequestAsync() at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)

When I remove the authentication service, or I do not use Electron, it works. It seems to be caused by the cookie "SameSite=None" since the secure cookie is not set to secure.

I have tried adding a cookie policy to the app service by using the following:
app.UseCookiePolicy(new CookiePolicyOptions { MinimumSameSitePolicy = SameSiteMode.Lax });
but this did not fix my issue. I also tried adding it to the authentication service:
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) .AddCookie(options => { options.Cookie.SameSite = SameSiteMode.Lax; }).AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAD")); but this also did not work

Steps to Reproduce:

  1. Register an app on Azure -> Microsoft EntraID
  2. Add Azure AD authentication to the app builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAD"));
  3. Run app and log in via Microsoft account.
  4. Set up electron
  5. Run app again and receive error message instead of login screen
Originally created by @ThomasStarnes on GitHub (May 3, 2024). * **Versions**: - Electron.NET: 23.6.2 - .NET: 7.0 - Node.JS: 20.12.2 * **Target**: Windows <!-- Enter your issue details below this comment. --> I'm working on a Blazor Server app and have been tasked with creating a desktop version of the app. I have been trying to use Electron.NET, but I am running into issues when authenticating through Azure AD while using Electron.NET. I'm receiving the following error: `stdout: fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HN2V44AL6L5H", Request id "0HN2V44AL6L5H:00000002": An unhandled exception was thrown by the application. System.Exception: An error was encountered while handling the remote login. ---> System.Exception: Correlation failed. --- End of inner exception stack trace --- at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler1.HandleRequestAsync() at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)` When I remove the authentication service, or I do not use Electron, it works. It seems to be caused by the cookie "SameSite=None" since the secure cookie is not set to secure. I have tried adding a cookie policy to the app service by using the following: `app.UseCookiePolicy(new CookiePolicyOptions { MinimumSameSitePolicy = SameSiteMode.Lax });` but this did not fix my issue. I also tried adding it to the authentication service: ` builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) .AddCookie(options => { options.Cookie.SameSite = SameSiteMode.Lax; }).AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAD"));` but this also did not work Steps to Reproduce: 1. Register an app on Azure -> Microsoft EntraID 2. Add Azure AD authentication to the app `builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAD"));` 3. Run app and log in via Microsoft account. 4. Set up electron 5. Run app again and receive error message instead of login screen
claunia added the bug label 2026-01-29 16:52:29 +00:00
Author
Owner

@umitkara commented on GitHub (May 27, 2024):

Hi. Having the same issue with OIDC and IdentityServer4 instead of AzureAD.

@umitkara commented on GitHub (May 27, 2024): Hi. Having the same issue with OIDC and IdentityServer4 instead of AzureAD.
Author
Owner

@LapinskasL commented on GitHub (Jun 25, 2024):

@umitkara Did you ever solve your issue?

@LapinskasL commented on GitHub (Jun 25, 2024): @umitkara Did you ever solve your issue?
Author
Owner

@umitkara commented on GitHub (Jul 5, 2024):

@umitkara Did you ever solve your issue?

Hi. Sorry for late response. Unfortunately no.

@umitkara commented on GitHub (Jul 5, 2024): > @umitkara Did you ever solve your issue? Hi. Sorry for late response. Unfortunately no.
Author
Owner

@FlorianRappl commented on GitHub (Oct 31, 2025):

Outdated - use ElectronNET.Core and ElectronNET.Core.AspNet.

See Wiki / What's New.

@FlorianRappl commented on GitHub (Oct 31, 2025): Outdated - use `ElectronNET.Core` and `ElectronNET.Core.AspNet`. See [Wiki / What's New](https://github.com/ElectronNET/Electron.NET/wiki/What's-New).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#945