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 ConfigService<AppConfiguration> ConfigService;
|
||||
private readonly DatabaseRepository<User> UserRepository;
|
||||
private readonly ImplementationService ImplementationService;
|
||||
private readonly ILogger<AuthController> Logger;
|
||||
private readonly IOAuth2Provider[] OAuth2Providers;
|
||||
private readonly IAuthInterceptor[] AuthInterceptors;
|
||||
|
||||
public AuthController(
|
||||
OAuth2Service oAuth2Service,
|
||||
TokenHelper tokenHelper,
|
||||
DatabaseRepository<User> userRepository,
|
||||
ConfigService<AppConfiguration> configService,
|
||||
ImplementationService implementationService,
|
||||
ILogger<AuthController> logger)
|
||||
ILogger<AuthController> logger,
|
||||
IOAuth2Provider[] oAuth2Providers,
|
||||
IAuthInterceptor[] authInterceptors)
|
||||
{
|
||||
OAuth2Service = oAuth2Service;
|
||||
TokenHelper = tokenHelper;
|
||||
UserRepository = userRepository;
|
||||
ConfigService = configService;
|
||||
ImplementationService = implementationService;
|
||||
Logger = logger;
|
||||
OAuth2Providers = oAuth2Providers;
|
||||
AuthInterceptors = authInterceptors;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -59,7 +62,7 @@ public class AuthController : Controller
|
||||
var accessData = await OAuth2Service.RequestAccess(request.Code);;
|
||||
|
||||
// Find oauth2 provider
|
||||
var provider = ImplementationService.Get<IOAuth2Provider>().FirstOrDefault();
|
||||
var provider = OAuth2Providers.FirstOrDefault();
|
||||
|
||||
if (provider == null)
|
||||
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);
|
||||
|
||||
// Allow plugins to intercept access calls
|
||||
var interceptors = ImplementationService.Get<IAuthInterceptor>();
|
||||
|
||||
if (interceptors.Any(interceptor => !interceptor.AllowAccess(user, HttpContext.RequestServices)))
|
||||
if (AuthInterceptors.Any(interceptor => !interceptor.AllowAccess(user, HttpContext.RequestServices)))
|
||||
throw new HttpApiException("Unable to get access token", 401);
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Find oauth2 provider
|
||||
var provider = ImplementationService.Get<IOAuth2Provider>().FirstOrDefault();
|
||||
var provider = OAuth2Providers.FirstOrDefault();
|
||||
|
||||
if (provider == null)
|
||||
throw new HttpApiException("No oauth2 provider has been registered", 500);
|
||||
@@ -162,9 +163,7 @@ public class AuthController : Controller
|
||||
return false;
|
||||
|
||||
// Allow plugins to intercept the refresh call
|
||||
var interceptors = ImplementationService.Get<IAuthInterceptor>();
|
||||
|
||||
if (interceptors.Any(interceptor => !interceptor.AllowRefresh(user, serviceProvider)))
|
||||
if (AuthInterceptors.Any(interceptor => !interceptor.AllowRefresh(user, serviceProvider)))
|
||||
return false;
|
||||
|
||||
// Check if it's time to resync with the oauth2 provider
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</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.Tailwind" Version="1.0.7" />
|
||||
<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="Swashbuckle.AspNetCore" Version="6.4.0"/>
|
||||
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
@@ -7,6 +8,7 @@ using MoonCore.Extended.OAuth2.ApiServer;
|
||||
using MoonCore.Extensions;
|
||||
using MoonCore.Helpers;
|
||||
using MoonCore.Models;
|
||||
using MoonCore.PluginFramework.Extensions;
|
||||
using MoonCore.PluginFramework.Services;
|
||||
using MoonCore.Services;
|
||||
using Moonlight.ApiServer.Configuration;
|
||||
@@ -16,6 +18,7 @@ using Moonlight.ApiServer.Helpers;
|
||||
using Moonlight.ApiServer.Helpers.Authentication;
|
||||
using Moonlight.ApiServer.Http.Middleware;
|
||||
using Moonlight.ApiServer.Implementations.OAuth2;
|
||||
using Moonlight.ApiServer.Interfaces.Auth;
|
||||
using Moonlight.ApiServer.Interfaces.OAuth2;
|
||||
|
||||
// Prepare file system
|
||||
@@ -186,12 +189,13 @@ if (configService.Get().Development.EnableApiDocs)
|
||||
}
|
||||
|
||||
// Implementation service
|
||||
var implementationService = new ImplementationService();
|
||||
|
||||
if(config.Authentication.UseLocalOAuth2)
|
||||
implementationService.Register<IOAuth2Provider, LocalOAuth2Provider>();
|
||||
|
||||
builder.Services.AddSingleton(implementationService);
|
||||
builder.Services.AddPlugins(configuration =>
|
||||
{
|
||||
configuration.AddInterface<IOAuth2Provider>();
|
||||
configuration.AddInterface<IAuthInterceptor>();
|
||||
|
||||
configuration.AddAssembly(Assembly.GetEntryAssembly()!);
|
||||
}, logger);
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user