Moving login files to the authentication module

This commit is contained in:
Zoe Roux 2021-05-13 21:04:38 +02:00
parent 21e354bf00
commit 23e44d5efe
9 changed files with 63 additions and 23 deletions

View File

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using IdentityServer4.Extensions;
using IdentityServer4.Models;
using IdentityServer4.Services;
@ -13,9 +15,11 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Logging;
using SameSiteMode = Microsoft.AspNetCore.Http.SameSiteMode;
namespace Kyoo.Authentication
{
@ -80,7 +84,7 @@ namespace Kyoo.Authentication
/// <inheritdoc />
public void Configure(IServiceCollection services, ICollection<Type> availableTypes)
{
string publicUrl = _configuration.GetValue<string>("public_url").TrimEnd('/');
string publicUrl = _configuration.GetValue<string>("publicUrl").TrimEnd('/');
if (_environment.IsDevelopment())
IdentityModelEventSource.ShowPII = true;
@ -141,11 +145,26 @@ namespace Kyoo.Authentication
app.UseAuthentication();
app.Use((ctx, next) =>
{
ctx.SetIdentityServerOrigin(_configuration.GetValue<string>("public_url"));
ctx.SetIdentityServerOrigin(_configuration.GetValue<string>("publicUrl").TrimEnd('/'));
return next();
});
app.UseIdentityServer();
app.UseAuthorization();
PhysicalFileProvider provider = new(Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!,
"login"));
app.UseDefaultFiles(new DefaultFilesOptions
{
RequestPath = new PathString("/login"),
FileProvider = provider,
RedirectToAppendTrailingSlash = true
});
app.UseStaticFiles(new StaticFileOptions
{
RequestPath = new PathString("/login"),
FileProvider = provider
});
}
}
}

View File

@ -13,6 +13,7 @@
<Authors>Zoe Roux</Authors>
<RepositoryUrl>https://github.com/AnonymusRaccoon/Kyoo</RepositoryUrl>
<LangVersion>default</LangVersion>
<LoginRoot>../Kyoo.WebLogin/</LoginRoot>
</PropertyGroup>
<ItemGroup>
@ -21,12 +22,29 @@
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Kyoo.Common/Kyoo.Common.csproj">
<PrivateAssets>all</PrivateAssets>
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<LoginFiles Include="$(LoginRoot)**" Visible="false" />
</ItemGroup>
<Target Name="Publish login files" AfterTargets="ComputeFilesToPublish">
<ItemGroup>
<ResolvedFileToPublish Include="@(LoginFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>login/%(LoginFiles.RecursiveDir)%(LoginFiles.Filename)%(LoginFiles.Extension)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
<Target Name="Prepare static files" AfterTargets="Build" Condition="$(Configuration) == 'Debug'">
<Copy SourceFiles="@(LoginFiles)" DestinationFolder="$(OutputPath)/login/%(RecursiveDir)" />
</Target>
</Project>

View File

@ -21,7 +21,7 @@ namespace Kyoo.CommonApi
public CrudApi(IRepository<T> repository, IConfiguration configuration)
{
_repository = repository;
BaseURL = configuration.GetValue<string>("public_url").TrimEnd('/');
BaseURL = configuration.GetValue<string>("publicUrl").TrimEnd('/');
}

View File

@ -27,9 +27,15 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Kyoo.CommonAPI/Kyoo.CommonAPI.csproj">
</ProjectReference>
<ProjectReference Include="../Kyoo.CommonAPI/Kyoo.CommonAPI.csproj">
<PrivateAssets>all</PrivateAssets>
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="../Kyoo.Common/Kyoo.Common.csproj">
<PrivateAssets>all</PrivateAssets>
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>
</Project>

View File

@ -218,6 +218,7 @@ namespace Kyoo.Controllers
});
if (existing != null)
return existing;
// TODO load the assembly from the common folder if the file exists (this would allow shared libraries)
string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
if (assemblyPath != null)
return LoadFromAssemblyPath(assemblyPath);

View File

@ -6,7 +6,6 @@
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
<SpaRoot>../Kyoo.WebApp/</SpaRoot>
<LoginRoot>../Kyoo.WebLogin/</LoginRoot>
<TranscoderRoot>../Kyoo.Transcoder/</TranscoderRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules/**</DefaultItemExcludes>
@ -52,7 +51,6 @@
<ItemGroup>
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules/**" Visible="false" />
<StaticFiles Include="$(SpaRoot)static/**" Visible="false" />
<LoginFiles Include="$(LoginRoot)**" Visible="false" />
<Content Remove="$(SpaRoot)**" />
</ItemGroup>
@ -72,18 +70,13 @@
</ItemGroup>
</Target>
<Target Name="Publish static and login" AfterTargets="ComputeFilesToPublish">
<Target Name="Publish static files" AfterTargets="ComputeFilesToPublish">
<ItemGroup>
<ResolvedFileToPublish Include="@(StaticFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>wwwroot/%(StaticFiles.RecursiveDir)%(StaticFiles.Filename)%(StaticFiles.Extension)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
<ResolvedFileToPublish Include="@(LoginFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>wwwroot/login/%(LoginFiles.RecursiveDir)%(LoginFiles.Filename)%(LoginFiles.Extension)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
@ -91,9 +84,8 @@
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
</Target>
<Target Name="Prepare static and login pages" AfterTargets="Build" Condition="$(Configuration) == 'Debug'">
<Target Name="Prepare static files" AfterTargets="Build" Condition="$(Configuration) == 'Debug'">
<Copy SourceFiles="@(StaticFiles)" DestinationFolder="$(OutputPath)/wwwroot/%(RecursiveDir)" />
<Copy SourceFiles="@(LoginFiles)" DestinationFolder="$(OutputPath)/wwwroot/login/%(RecursiveDir)" />
</Target>
<Target Name="Symlink views to output - Linux" AfterTargets="Build" Condition="$(Configuration) == 'Debug' And $(OS) == 'Unix'">

View File

@ -1,5 +1,6 @@
using System;
using System.IO;
using Kyoo.Authentication;
using Kyoo.Controllers;
using Kyoo.Models;
using Kyoo.Postgresql;
@ -46,7 +47,11 @@ namespace Kyoo
_configuration = configuration;
_plugins = new PluginManager(hostProvider, _configuration, loggerFactory.CreateLogger<PluginManager>());
_plugins.LoadPlugins(new IPlugin[] {new CoreModule(), new PostgresModule(configuration, host)});
// TODO remove postgres from here and load it like a normal plugin.
_plugins.LoadPlugins(new IPlugin[] {new CoreModule(),
new PostgresModule(configuration, host),
new AuthenticationModule(configuration, loggerFactory, host)
});
}
/// <summary>
@ -55,7 +60,7 @@ namespace Kyoo
/// <param name="services">The service collection to fill.</param>
public void ConfigureServices(IServiceCollection services)
{
string publicUrl = _configuration.GetValue<string>("public_url");
string publicUrl = _configuration.GetValue<string>("publicUrl");
services.AddMvc().AddControllersAsServices();
@ -100,7 +105,6 @@ namespace Kyoo
FileExtensionContentTypeProvider contentTypeProvider = new();
contentTypeProvider.Mappings[".data"] = "application/octet-stream";
app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = contentTypeProvider,

View File

@ -25,7 +25,7 @@ namespace Kyoo.Api
public LibraryItemApi(ILibraryItemRepository libraryItems, IConfiguration configuration)
{
_libraryItems = libraryItems;
_baseURL = configuration.GetValue<string>("public_url").TrimEnd('/');
_baseURL = configuration.GetValue<string>("publicUrl").TrimEnd('/');
}
[HttpGet]

View File

@ -1,6 +1,6 @@
{
"server.urls": "http://*:5000",
"public_url": "http://localhost:5000/",
"publicUrl": "http://localhost:5000/",
"database": {
"postgres": {