Changed auth success ui. Switched to new interface service. Upgraded mooncore versions
This commit is contained in:
@@ -26,23 +26,26 @@ public class AuthController : Controller
|
|||||||
private readonly TokenHelper TokenHelper;
|
private readonly TokenHelper TokenHelper;
|
||||||
private readonly ConfigService<AppConfiguration> ConfigService;
|
private readonly ConfigService<AppConfiguration> ConfigService;
|
||||||
private readonly DatabaseRepository<User> UserRepository;
|
private readonly DatabaseRepository<User> UserRepository;
|
||||||
private readonly ImplementationService ImplementationService;
|
|
||||||
private readonly ILogger<AuthController> Logger;
|
private readonly ILogger<AuthController> Logger;
|
||||||
|
private readonly IOAuth2Provider[] OAuth2Providers;
|
||||||
|
private readonly IAuthInterceptor[] AuthInterceptors;
|
||||||
|
|
||||||
public AuthController(
|
public AuthController(
|
||||||
OAuth2Service oAuth2Service,
|
OAuth2Service oAuth2Service,
|
||||||
TokenHelper tokenHelper,
|
TokenHelper tokenHelper,
|
||||||
DatabaseRepository<User> userRepository,
|
DatabaseRepository<User> userRepository,
|
||||||
ConfigService<AppConfiguration> configService,
|
ConfigService<AppConfiguration> configService,
|
||||||
ImplementationService implementationService,
|
ILogger<AuthController> logger,
|
||||||
ILogger<AuthController> logger)
|
IOAuth2Provider[] oAuth2Providers,
|
||||||
|
IAuthInterceptor[] authInterceptors)
|
||||||
{
|
{
|
||||||
OAuth2Service = oAuth2Service;
|
OAuth2Service = oAuth2Service;
|
||||||
TokenHelper = tokenHelper;
|
TokenHelper = tokenHelper;
|
||||||
UserRepository = userRepository;
|
UserRepository = userRepository;
|
||||||
ConfigService = configService;
|
ConfigService = configService;
|
||||||
ImplementationService = implementationService;
|
|
||||||
Logger = logger;
|
Logger = logger;
|
||||||
|
OAuth2Providers = oAuth2Providers;
|
||||||
|
AuthInterceptors = authInterceptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@@ -59,7 +62,7 @@ public class AuthController : Controller
|
|||||||
var accessData = await OAuth2Service.RequestAccess(request.Code);;
|
var accessData = await OAuth2Service.RequestAccess(request.Code);;
|
||||||
|
|
||||||
// Find oauth2 provider
|
// Find oauth2 provider
|
||||||
var provider = ImplementationService.Get<IOAuth2Provider>().FirstOrDefault();
|
var provider = OAuth2Providers.FirstOrDefault();
|
||||||
|
|
||||||
if (provider == null)
|
if (provider == null)
|
||||||
throw new HttpApiException("No oauth2 provider has been registered", 500);
|
throw new HttpApiException("No oauth2 provider has been registered", 500);
|
||||||
@@ -71,9 +74,7 @@ public class AuthController : Controller
|
|||||||
throw new HttpApiException("The oauth2 provider was unable to authenticate you", 401);
|
throw new HttpApiException("The oauth2 provider was unable to authenticate you", 401);
|
||||||
|
|
||||||
// Allow plugins to intercept access calls
|
// Allow plugins to intercept access calls
|
||||||
var interceptors = ImplementationService.Get<IAuthInterceptor>();
|
if (AuthInterceptors.Any(interceptor => !interceptor.AllowAccess(user, HttpContext.RequestServices)))
|
||||||
|
|
||||||
if (interceptors.Any(interceptor => !interceptor.AllowAccess(user, HttpContext.RequestServices)))
|
|
||||||
throw new HttpApiException("Unable to get access token", 401);
|
throw new HttpApiException("Unable to get access token", 401);
|
||||||
|
|
||||||
// Save oauth2 refresh and access tokens for later use (re-authentication etc.).
|
// Save oauth2 refresh and access tokens for later use (re-authentication etc.).
|
||||||
@@ -144,7 +145,7 @@ public class AuthController : Controller
|
|||||||
private bool ProcessRefreshData(Dictionary<string, JsonElement> refreshTokenData, Dictionary<string, object> newData, IServiceProvider serviceProvider)
|
private bool ProcessRefreshData(Dictionary<string, JsonElement> refreshTokenData, Dictionary<string, object> newData, IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
// Find oauth2 provider
|
// Find oauth2 provider
|
||||||
var provider = ImplementationService.Get<IOAuth2Provider>().FirstOrDefault();
|
var provider = OAuth2Providers.FirstOrDefault();
|
||||||
|
|
||||||
if (provider == null)
|
if (provider == null)
|
||||||
throw new HttpApiException("No oauth2 provider has been registered", 500);
|
throw new HttpApiException("No oauth2 provider has been registered", 500);
|
||||||
@@ -162,9 +163,7 @@ public class AuthController : Controller
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Allow plugins to intercept the refresh call
|
// Allow plugins to intercept the refresh call
|
||||||
var interceptors = ImplementationService.Get<IAuthInterceptor>();
|
if (AuthInterceptors.Any(interceptor => !interceptor.AllowRefresh(user, serviceProvider)))
|
||||||
|
|
||||||
if (interceptors.Any(interceptor => !interceptor.AllowRefresh(user, serviceProvider)))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check if it's time to resync with the oauth2 provider
|
// Check if it's time to resync with the oauth2 provider
|
||||||
|
|||||||
@@ -12,11 +12,11 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="MoonCore" Version="1.6.6" />
|
<PackageReference Include="MoonCore" Version="1.6.7" />
|
||||||
<PackageReference Include="MoonCore.Blazor" Version="1.2.4" />
|
<PackageReference Include="MoonCore.Blazor" Version="1.2.4" />
|
||||||
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.0.7" />
|
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.0.7" />
|
||||||
<PackageReference Include="MoonCore.Extended" Version="1.1.2" />
|
<PackageReference Include="MoonCore.Extended" Version="1.1.2" />
|
||||||
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.0" />
|
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.2" />
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
|
||||||
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
|
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using MoonCore.Extended.Abstractions;
|
using MoonCore.Extended.Abstractions;
|
||||||
@@ -7,6 +8,7 @@ using MoonCore.Extended.OAuth2.ApiServer;
|
|||||||
using MoonCore.Extensions;
|
using MoonCore.Extensions;
|
||||||
using MoonCore.Helpers;
|
using MoonCore.Helpers;
|
||||||
using MoonCore.Models;
|
using MoonCore.Models;
|
||||||
|
using MoonCore.PluginFramework.Extensions;
|
||||||
using MoonCore.PluginFramework.Services;
|
using MoonCore.PluginFramework.Services;
|
||||||
using MoonCore.Services;
|
using MoonCore.Services;
|
||||||
using Moonlight.ApiServer.Configuration;
|
using Moonlight.ApiServer.Configuration;
|
||||||
@@ -16,6 +18,7 @@ using Moonlight.ApiServer.Helpers;
|
|||||||
using Moonlight.ApiServer.Helpers.Authentication;
|
using Moonlight.ApiServer.Helpers.Authentication;
|
||||||
using Moonlight.ApiServer.Http.Middleware;
|
using Moonlight.ApiServer.Http.Middleware;
|
||||||
using Moonlight.ApiServer.Implementations.OAuth2;
|
using Moonlight.ApiServer.Implementations.OAuth2;
|
||||||
|
using Moonlight.ApiServer.Interfaces.Auth;
|
||||||
using Moonlight.ApiServer.Interfaces.OAuth2;
|
using Moonlight.ApiServer.Interfaces.OAuth2;
|
||||||
|
|
||||||
// Prepare file system
|
// Prepare file system
|
||||||
@@ -186,12 +189,13 @@ if (configService.Get().Development.EnableApiDocs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implementation service
|
// Implementation service
|
||||||
var implementationService = new ImplementationService();
|
builder.Services.AddPlugins(configuration =>
|
||||||
|
{
|
||||||
if(config.Authentication.UseLocalOAuth2)
|
configuration.AddInterface<IOAuth2Provider>();
|
||||||
implementationService.Register<IOAuth2Provider, LocalOAuth2Provider>();
|
configuration.AddInterface<IAuthInterceptor>();
|
||||||
|
|
||||||
builder.Services.AddSingleton(implementationService);
|
configuration.AddAssembly(Assembly.GetEntryAssembly()!);
|
||||||
|
}, logger);
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.6"/>
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.6"/>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.6" PrivateAssets="all"/>
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.6" PrivateAssets="all"/>
|
||||||
<PackageReference Include="MoonCore" Version="1.6.6" />
|
<PackageReference Include="MoonCore" Version="1.6.7" />
|
||||||
<PackageReference Include="MoonCore.Blazor" Version="1.2.4" />
|
<PackageReference Include="MoonCore.Blazor" Version="1.2.4" />
|
||||||
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.0" />
|
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.2" />
|
||||||
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.0.7" />
|
<PackageReference Include="MoonCore.Blazor.Tailwind" Version="1.0.7" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||||
using MoonCore.Blazor.Extensions;
|
using MoonCore.Blazor.Extensions;
|
||||||
@@ -9,6 +10,7 @@ using MoonCore.Exceptions;
|
|||||||
using MoonCore.Extensions;
|
using MoonCore.Extensions;
|
||||||
using MoonCore.Helpers;
|
using MoonCore.Helpers;
|
||||||
using MoonCore.Models;
|
using MoonCore.Models;
|
||||||
|
using MoonCore.PluginFramework.Extensions;
|
||||||
using MoonCore.PluginFramework.Services;
|
using MoonCore.PluginFramework.Services;
|
||||||
using Moonlight.Client.Implementations;
|
using Moonlight.Client.Implementations;
|
||||||
using Moonlight.Client.Interfaces;
|
using Moonlight.Client.Interfaces;
|
||||||
@@ -103,16 +105,16 @@ builder.Services.AutoAddServices<Program>();
|
|||||||
FormComponentRepository.Set<string, StringComponent>();
|
FormComponentRepository.Set<string, StringComponent>();
|
||||||
FormComponentRepository.Set<int, IntComponent>();
|
FormComponentRepository.Set<int, IntComponent>();
|
||||||
|
|
||||||
// Implementation service
|
// Interface service
|
||||||
var implementationService = new ImplementationService();
|
builder.Services.AddPlugins(configuration =>
|
||||||
|
{
|
||||||
implementationService.Register<ISidebarItemProvider, DefaultSidebarItemProvider>();
|
configuration.AddAssembly(Assembly.GetEntryAssembly()!);
|
||||||
|
|
||||||
var authUiHandler = new AuthenticationUiHandler();
|
configuration.AddInterface<IAppLoader>();
|
||||||
implementationService.Register<IAppScreen>(authUiHandler);
|
configuration.AddInterface<IAppScreen>();
|
||||||
implementationService.Register<IAppLoader>(authUiHandler);
|
|
||||||
|
configuration.AddInterface<ISidebarItemProvider>();
|
||||||
builder.Services.AddSingleton(implementationService);
|
}, logger);
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,11 @@
|
|||||||
|
|
||||||
@inherits LayoutComponentBase
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
@inject ImplementationService ImplementationService
|
|
||||||
@inject IdentityService IdentityService
|
@inject IdentityService IdentityService
|
||||||
@inject IServiceProvider ServiceProvider
|
@inject IServiceProvider ServiceProvider
|
||||||
@inject ILogger<MainLayout> Logger
|
@inject ILogger<MainLayout> Logger
|
||||||
|
@inject IAppLoader[] AppLoaders
|
||||||
|
@inject IAppScreen[] AppScreens
|
||||||
|
|
||||||
@if (IsLoading)
|
@if (IsLoading)
|
||||||
{
|
{
|
||||||
@@ -98,8 +99,7 @@ else
|
|||||||
|
|
||||||
private async Task RunLoaders()
|
private async Task RunLoaders()
|
||||||
{
|
{
|
||||||
var appLoaders = ImplementationService
|
var appLoaders = AppLoaders
|
||||||
.Get<IAppLoader>()
|
|
||||||
.OrderBy(x => x.Priority);
|
.OrderBy(x => x.Priority);
|
||||||
|
|
||||||
foreach (var loader in appLoaders) //TODO: Measure performance of every loader?
|
foreach (var loader in appLoaders) //TODO: Measure performance of every loader?
|
||||||
@@ -120,8 +120,7 @@ else
|
|||||||
{
|
{
|
||||||
CurrentScreen = null;
|
CurrentScreen = null;
|
||||||
|
|
||||||
var appScreens = ImplementationService
|
var appScreens = AppScreens
|
||||||
.Get<IAppScreen>()
|
|
||||||
.OrderBy(x => x.Priority);
|
.OrderBy(x => x.Priority);
|
||||||
|
|
||||||
foreach (var screen in appScreens)
|
foreach (var screen in appScreens)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
@inject IdentityService IdentityService
|
@inject IdentityService IdentityService
|
||||||
@inject ImplementationService ImplementationService
|
@inject ISidebarItemProvider[] SidebarItemProviders
|
||||||
|
|
||||||
@{
|
@{
|
||||||
var url = new Uri(Navigation.Uri);
|
var url = new Uri(Navigation.Uri);
|
||||||
@@ -168,7 +168,7 @@
|
|||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
Items = ImplementationService.Get<ISidebarItemProvider>()
|
Items = SidebarItemProviders
|
||||||
.SelectMany(x => x.Get())
|
.SelectMany(x => x.Get())
|
||||||
.Where(x => x.Permission == null || (x.Permission != null && IdentityService.HasPermission(x.Permission)))
|
.Where(x => x.Permission == null || (x.Permission != null && IdentityService.HasPermission(x.Permission)))
|
||||||
.GroupBy(x => x.Group ?? "")
|
.GroupBy(x => x.Group ?? "")
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
@inject HttpClient HttpClient
|
@inject HttpClient HttpClient
|
||||||
@inject LocalStorageService LocalStorageService
|
@inject LocalStorageService LocalStorageService
|
||||||
|
|
||||||
|
@inject ILogger<AuthenticationScreen> Logger
|
||||||
|
|
||||||
@if (Code == null)
|
@if (Code == null)
|
||||||
{
|
{
|
||||||
<div class="h-full w-full min-h-[100dvh] flex items-center justify-center px-5 md:px-0">
|
<div class="h-full w-full min-h-[100dvh] flex items-center justify-center px-5 md:px-0">
|
||||||
@@ -53,14 +55,10 @@ else
|
|||||||
@if (IsHandlingDone)
|
@if (IsHandlingDone)
|
||||||
{
|
{
|
||||||
<div class="sm:mx-auto sm:w-full sm:max-w-sm mb-5">
|
<div class="sm:mx-auto sm:w-full sm:max-w-sm mb-5">
|
||||||
<img class="mx-auto h-16 w-auto" src="/logolong.webp" alt="Moonlight">
|
<img class="mx-auto w-auto h-32" src="/svg/completed.svg" alt="Completed illustration">
|
||||||
<h2 class="mt-6 text-center text-2xl font-bold leading-9 tracking-tight text-gray-100">Login to access your account</h2>
|
<h2 class="mt-6 text-center text-2xl font-semibold leading-9 tracking-tight text-gray-100">
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex justify-center">
|
|
||||||
<p class="mt-3 text-center text-md text-gray-400">
|
|
||||||
Login successful. You can close this window now
|
Login successful. You can close this window now
|
||||||
</p>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -91,25 +89,35 @@ else
|
|||||||
if (Code == null)
|
if (Code == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var authHandleData = await HttpApiClient.PostJson<OAuth2HandleResponse>("api/auth", new OAuth2HandleRequest()
|
|
||||||
{
|
|
||||||
Code = Code
|
|
||||||
});
|
|
||||||
|
|
||||||
await LocalStorageService.SetString("AccessToken", authHandleData.AccessToken);
|
|
||||||
await LocalStorageService.SetString("RefreshToken", authHandleData.RefreshToken);
|
|
||||||
await LocalStorageService.Set("ExpiresAt", authHandleData.ExpiresAt);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await WindowService.Close();
|
var authHandleData = await HttpApiClient.PostJson<OAuth2HandleResponse>("api/auth", new OAuth2HandleRequest()
|
||||||
}
|
{
|
||||||
finally
|
Code = Code
|
||||||
{
|
});
|
||||||
|
|
||||||
|
// Save the auth handle data
|
||||||
|
await LocalStorageService.SetString("AccessToken", authHandleData.AccessToken);
|
||||||
|
await LocalStorageService.SetString("RefreshToken", authHandleData.RefreshToken);
|
||||||
|
await LocalStorageService.Set("ExpiresAt", authHandleData.ExpiresAt);
|
||||||
|
|
||||||
|
// Update UI
|
||||||
IsHandlingDone = true;
|
IsHandlingDone = true;
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(2));
|
||||||
|
|
||||||
Navigation.NavigateTo("/", true);
|
try
|
||||||
|
{
|
||||||
|
await WindowService.Close();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo("/", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.LogError("An unhandled error occured while handling oauth2 code: {e}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
Moonlight.Client/wwwroot/svg/completed.svg
Normal file
1
Moonlight.Client/wwwroot/svg/completed.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 12 KiB |
Reference in New Issue
Block a user