diff --git a/src/Security/src/AXOpen.Security/IdentityComponentsEndpointRouteBuilderExtensions.cs b/src/Security/src/AXOpen.Security/IdentityComponentsEndpointRouteBuilderExtensions.cs index 10be4158b..0feae853a 100644 --- a/src/Security/src/AXOpen.Security/IdentityComponentsEndpointRouteBuilderExtensions.cs +++ b/src/Security/src/AXOpen.Security/IdentityComponentsEndpointRouteBuilderExtensions.cs @@ -108,6 +108,16 @@ public static IEndpointRouteBuilder MapAdditionalIdentityEndpoints(this IEndpoin if (context.User.Identity?.Name != null) currentUser = await userManager.FindByNameAsync(context.User.Identity.Name); + if (currentUser != null) + { + if (logoutHandler != null) + { + string ipAddress = GetClientIpAddress(context); + await logoutHandler(currentUser.UserName!, ipAddress); + } + await signInManager.SignOutAsync(); + } + // Find user by hashed external auth ID var users = userManager.Users.Where(u => TokenHasher.VerifyToken(externalAuthId, u.ExternalAuthId)).ToList(); if (!users.Any() || users.Count > 1) @@ -115,31 +125,9 @@ public static IEndpointRouteBuilder MapAdditionalIdentityEndpoints(this IEndpoin var user = users.First(); - if (currentUser != null) - { - // User is already logged in - if (TokenHasher.VerifyToken(externalAuthId, currentUser.ExternalAuthId)) - { - // Same user - log out - if (logoutHandler != null) - { - string ipAddress = GetClientIpAddress(context); - await logoutHandler(currentUser.UserName!, ipAddress); - } - await signInManager.SignOutAsync(); + if (currentUser != null) // User is already logged in + if (TokenHasher.VerifyToken(externalAuthId, currentUser.ExternalAuthId)) // Same user - only log out return TypedResults.LocalRedirect(string.IsNullOrEmpty(returnUrl) ? "/" : !returnUrl.StartsWith("/") ? "/" + returnUrl : returnUrl.StartsWith("//") ? "/" + returnUrl.TrimStart('/') : returnUrl); - } - else - { - // Different user - log out current and log in new - if (logoutHandler != null) - { - string ipAddress = GetClientIpAddress(context); - await logoutHandler(currentUser.UserName!, ipAddress); - } - await signInManager.SignOutAsync(); - } - } // Sign in the user await signInManager.SignInAsync(user, isPersistent: false); diff --git a/src/Security/src/AXOpen.Security/Services/SerialService.cs b/src/Security/src/AXOpen.Security/Services/SerialService.cs index 150bc9ac3..72c820605 100644 --- a/src/Security/src/AXOpen.Security/Services/SerialService.cs +++ b/src/Security/src/AXOpen.Security/Services/SerialService.cs @@ -66,7 +66,15 @@ public async Task OpenPortAsync(int baudRate, bool onlyPreviouslyAuthorize if(_module == null) _module = await _jsRuntime.InvokeAsync("import", "./_content/AXOpen.Security.Blazor/js/SerialCommunication.js"); - int operationStatus = await _module.InvokeAsync("openPortAsync", _selfRef, onlyPreviouslyAuthorizedPort, baudRate, 512, dataBits, flowControlString, parityString, stopBits); + + int operationStatus = 0; + try + { + operationStatus = await _module.InvokeAsync("openPortAsync", _selfRef, onlyPreviouslyAuthorizedPort, baudRate, 512, dataBits, flowControlString, parityString, stopBits); + } + catch (Exception ex) + { + } switch (operationStatus) {