From 943adec3a0e6503966e85ab2008cacf55fc33eb6 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Thu, 13 May 2021 07:58:57 -0400 Subject: [PATCH] fixes for running on WebAssembly --- Oqtane.Client/Program.cs | 2 +- .../IdentityAuthenticationStateProvider.cs | 13 +++++++------ Oqtane.Server/Controllers/UserController.cs | 2 +- Oqtane.Server/Pages/_Host.cshtml | 9 ++++++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Oqtane.Client/Program.cs b/Oqtane.Client/Program.cs index 3ce0058f..3ae04bd8 100644 --- a/Oqtane.Client/Program.cs +++ b/Oqtane.Client/Program.cs @@ -120,7 +120,7 @@ namespace Oqtane.Client var assemblies = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToList(); // get assemblies from server and load into client app domain - var zip = await http.GetByteArrayAsync($"/~/api/Installation/load"); + var zip = await http.GetByteArrayAsync($"/api/Installation/load"); // asemblies and debug symbols are packaged in a zip file using (ZipArchive archive = new ZipArchive(new MemoryStream(zip))) diff --git a/Oqtane.Client/Providers/IdentityAuthenticationStateProvider.cs b/Oqtane.Client/Providers/IdentityAuthenticationStateProvider.cs index cbfbaad9..cbe48a4b 100644 --- a/Oqtane.Client/Providers/IdentityAuthenticationStateProvider.cs +++ b/Oqtane.Client/Providers/IdentityAuthenticationStateProvider.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Http; using System.Net.Http.Json; using System.Security.Claims; @@ -28,12 +28,12 @@ namespace Oqtane.Providers public override async Task GetAuthenticationStateAsync() { - // get HttpClient lazily from IServiceProvider as you cannot use standard dependency injection due to the AuthenticationStateProvider being initialized prior to NavigationManager ( https://github.com/aspnet/AspNetCore/issues/11867 ) - var http = _serviceProvider.GetRequiredService(); - string apiurl = "/~/api/User/authenticate"; - User user = await http.GetFromJsonAsync(apiurl); - ClaimsIdentity identity = new ClaimsIdentity(); + + // get HttpClient lazily from IServiceProvider as you cannot use standard dependency injection due to the AuthenticationStateProvider being initialized prior to NavigationManager(https://github.com/aspnet/AspNetCore/issues/11867 ) + var http = _serviceProvider.GetRequiredService(); + string apiurl = "/api/User/authenticate"; + User user = await http.GetFromJsonAsync(apiurl); if (user.IsAuthenticated) { identity = new ClaimsIdentity("Identity.Application"); @@ -44,6 +44,7 @@ namespace Oqtane.Providers identity.AddClaim(new Claim(ClaimTypes.Role, role)); } } + return new AuthenticationState(new ClaimsPrincipal(identity)); } diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index cc1972c0..bd36b6df 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -444,7 +444,7 @@ namespace Oqtane.Controllers return user; } - // GET api//current + // GET api//authenticate [HttpGet("authenticate")] public User Authenticate() { diff --git a/Oqtane.Server/Pages/_Host.cshtml b/Oqtane.Server/Pages/_Host.cshtml index df1d7a3a..4a7a4b07 100644 --- a/Oqtane.Server/Pages/_Host.cshtml +++ b/Oqtane.Server/Pages/_Host.cshtml @@ -22,7 +22,14 @@ @(Html.AntiForgeryToken()) - + @if (Configuration.GetSection("Runtime").Value == "WebAssembly") + { + + } + else + { + + }