Updated MoonCore dependencies. Switched to asp.net core native authentication scheme abstractions. Updated claim usage in frontend

This commit is contained in:
2025-08-20 16:16:31 +02:00
parent 60178dc54b
commit 3cc48fb8f7
42 changed files with 1459 additions and 858 deletions

View File

@@ -1,8 +1,13 @@
@using Moonlight.Client.UI.Layouts
@using Moonlight.Client.Services
@using Moonlight.Client.UI.Partials
@inject ApplicationAssemblyService ApplicationAssemblyService
<ApplicationRouter DefaultLayout="@typeof(MainLayout)"
AppAssembly="@typeof(App).Assembly"
AdditionalAssemblies="ApplicationAssemblyService.Assemblies" />
AdditionalAssemblies="ApplicationAssemblyService.Assemblies">
<LoginTemplate>
<LoginSelector />
</LoginTemplate>
</ApplicationRouter>

View File

@@ -1,4 +1,5 @@
@using Microsoft.AspNetCore.Components.Authorization
@using System.Security.Claims
@using Microsoft.AspNetCore.Components.Authorization
<div class="col-span-12 md:col-span-6">
<div class="font-medium leading-[1.1] tracking-tight">
@@ -18,7 +19,6 @@
protected override async Task OnInitializedAsync()
{
var identity = await AuthState;
var usernameClaim = identity.User.Claims.ToArray().First(x => x.Type == "username");
Username = usernameClaim.Value;
Username = identity.User.FindFirst(ClaimTypes.Name)!.Value;
}
}

View File

@@ -1,13 +1,11 @@
@using System.Security.Claims
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using MoonCore.Blazor.FlyonUi.Auth
@using Moonlight.Client.Interfaces
@using Moonlight.Client.Models
@using Moonlight.Client.UI.Layouts
@inject NavigationManager Navigation
@inject AuthenticationStateManager AuthStateManager
@inject IEnumerable<ISidebarItemProvider> SidebarItemProviders
@inject IAuthorizationService AuthorizationService
@@ -210,8 +208,8 @@
var authState = await AuthState;
Identity = authState.User;
Username = Identity.Claims.First(x => x.Type == "username").Value;
Email = Identity.Claims.First(x => x.Type == "email").Value;
Username = Identity.FindFirst(ClaimTypes.Name)!.Value;
Email = Identity.FindFirst(ClaimTypes.Email)!.Value;
var sidebarItems = new List<SidebarItem>();
@@ -260,8 +258,9 @@
return Task.CompletedTask;
}
private async Task Logout()
private Task Logout()
{
await AuthStateManager.Logout();
Navigation.NavigateTo("/api/auth/logout", true);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,87 @@
@using MoonCore.Helpers
@using Moonlight.Shared.Http.Responses.Auth
@inject HttpApiClient ApiClient
@inject NavigationManager Navigation
<div class="flex h-screen justify-center items-center">
<div class="sm:max-w-lg">
<div class="w-full card card-body text-center">
<LazyLoader EnableDefaultSpacing="false" Load="Load">
@if (ShowSelection)
{
<h5 class="card-title mb-2.5">Login to MoonCore</h5>
<p class="mb-4">Choose a login provider to start using the app</p>
<div class="flex flex-col w-full mt-5 gap-y-2.5">
@foreach (var scheme in AuthSchemes)
{
var config = Configs.GetValueOrDefault(scheme.Identifier);
if (config == null) // Ignore all schemes which have no ui configured
continue;
<button @onclick="() => Start(scheme)" class="btn btn-text w-full" style="background-color: @(config.Color)">
<img src="@config.IconUrl"
alt="scheme icon"
class="size-5 object-cover fill-base-content"/>
Sign in with @scheme.DisplayName
</button>
}
</div>
}
else
{
<div class="flex justify-center">
<span class="loading loading-spinner loading-xl"></span>
</div>
}
</LazyLoader>
</div>
</div>
</div>
@code
{
private AuthSchemeResponse[] AuthSchemes;
private Dictionary<string, AuthSchemeConfig> Configs = new();
private bool ShowSelection = false;
protected override void OnInitialized()
{
Configs["LocalAuth"] = new AuthSchemeConfig()
{
Color = "#7636e3",
IconUrl = "/placeholder.jpg"
};
}
private async Task Load(LazyLoader arg)
{
AuthSchemes = await ApiClient.GetJson<AuthSchemeResponse[]>(
"api/auth"
);
// If we only have one auth scheme available
// we want to auto redirect the user without
// showing the selection screen
if (AuthSchemes.Length == 1)
await Start(AuthSchemes[0]);
else
ShowSelection = true;
}
private Task Start(AuthSchemeResponse scheme)
{
Navigation.NavigateTo($"/api/auth/{scheme.Identifier}", true);
return Task.CompletedTask;
}
record AuthSchemeConfig
{
public string Color { get; set; }
public string IconUrl { get; set; }
}
}

View File

@@ -4,6 +4,7 @@
@using MoonCore.Helpers
@using Moonlight.Client.Implementations
@using MoonCore.Blazor.FlyonUi.Files.Manager
@using MoonCore.Blazor.FlyonUi.Files.Manager.Operations
@attribute [Authorize(Policy = "permissions:admin.system.overview")]
@@ -13,7 +14,8 @@
<NavTabs Index="2" Names="UiConstants.AdminNavNames" Links="UiConstants.AdminNavLinks"/>
</div>
<FileManager FsAccess="FsAccess" TransferChunkSize="TransferChunkSize" UploadLimit="UploadLimit"/>
<FileManager OnConfigure="OnConfigure" FsAccess="FsAccess" TransferChunkSize="TransferChunkSize"
UploadLimit="UploadLimit"/>
@code
{
@@ -21,9 +23,21 @@
private static readonly long TransferChunkSize = ByteConverter.FromMegaBytes(20).Bytes;
private static readonly long UploadLimit = ByteConverter.FromGigaBytes(20).Bytes;
protected override void OnInitialized()
{
FsAccess = new SystemFsAccess(ApiClient);
}
private void OnConfigure(FileManagerOptions options)
{
options.AddMultiOperation<DeleteOperation>();
options.AddMultiOperation<MoveOperation>();
options.AddMultiOperation<DownloadOperation>();
options.AddSingleOperation<RenameOperation>();
options.AddToolbarOperation<CreateFileOperation>();
options.AddToolbarOperation<CreateFolderOperation>();
}
}