mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 05:34:23 -04:00
Moving login files to the authentication module
This commit is contained in:
parent
21e354bf00
commit
23e44d5efe
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using IdentityServer4.Extensions;
|
using IdentityServer4.Extensions;
|
||||||
using IdentityServer4.Models;
|
using IdentityServer4.Models;
|
||||||
using IdentityServer4.Services;
|
using IdentityServer4.Services;
|
||||||
@ -13,9 +15,11 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.IdentityModel.Logging;
|
using Microsoft.IdentityModel.Logging;
|
||||||
|
using SameSiteMode = Microsoft.AspNetCore.Http.SameSiteMode;
|
||||||
|
|
||||||
namespace Kyoo.Authentication
|
namespace Kyoo.Authentication
|
||||||
{
|
{
|
||||||
@ -80,7 +84,7 @@ namespace Kyoo.Authentication
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Configure(IServiceCollection services, ICollection<Type> availableTypes)
|
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())
|
if (_environment.IsDevelopment())
|
||||||
IdentityModelEventSource.ShowPII = true;
|
IdentityModelEventSource.ShowPII = true;
|
||||||
@ -141,11 +145,26 @@ namespace Kyoo.Authentication
|
|||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.Use((ctx, next) =>
|
app.Use((ctx, next) =>
|
||||||
{
|
{
|
||||||
ctx.SetIdentityServerOrigin(_configuration.GetValue<string>("public_url"));
|
ctx.SetIdentityServerOrigin(_configuration.GetValue<string>("publicUrl").TrimEnd('/'));
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
app.UseIdentityServer();
|
app.UseIdentityServer();
|
||||||
app.UseAuthorization();
|
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
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,6 +13,7 @@
|
|||||||
<Authors>Zoe Roux</Authors>
|
<Authors>Zoe Roux</Authors>
|
||||||
<RepositoryUrl>https://github.com/AnonymusRaccoon/Kyoo</RepositoryUrl>
|
<RepositoryUrl>https://github.com/AnonymusRaccoon/Kyoo</RepositoryUrl>
|
||||||
<LangVersion>default</LangVersion>
|
<LangVersion>default</LangVersion>
|
||||||
|
<LoginRoot>../Kyoo.WebLogin/</LoginRoot>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -21,12 +22,29 @@
|
|||||||
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
|
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
|
||||||
<PackageReference Include="Portable.BouncyCastle" Version="1.8.10" />
|
<PackageReference Include="Portable.BouncyCastle" Version="1.8.10" />
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="../Kyoo.Common/Kyoo.Common.csproj">
|
<ProjectReference Include="../Kyoo.Common/Kyoo.Common.csproj">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<Private>false</Private>
|
<Private>false</Private>
|
||||||
|
<ExcludeAssets>runtime</ExcludeAssets>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</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>
|
</Project>
|
||||||
|
@ -21,7 +21,7 @@ namespace Kyoo.CommonApi
|
|||||||
public CrudApi(IRepository<T> repository, IConfiguration configuration)
|
public CrudApi(IRepository<T> repository, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
BaseURL = configuration.GetValue<string>("public_url").TrimEnd('/');
|
BaseURL = configuration.GetValue<string>("publicUrl").TrimEnd('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,9 +27,15 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="../Kyoo.CommonAPI/Kyoo.CommonAPI.csproj">
|
<ProjectReference Include="../Kyoo.CommonAPI/Kyoo.CommonAPI.csproj">
|
||||||
</ProjectReference>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<Private>false</Private>
|
||||||
|
<ExcludeAssets>runtime</ExcludeAssets>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="../Kyoo.Common/Kyoo.Common.csproj">
|
<ProjectReference Include="../Kyoo.Common/Kyoo.Common.csproj">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<Private>false</Private>
|
||||||
|
<ExcludeAssets>runtime</ExcludeAssets>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -218,6 +218,7 @@ namespace Kyoo.Controllers
|
|||||||
});
|
});
|
||||||
if (existing != null)
|
if (existing != null)
|
||||||
return existing;
|
return existing;
|
||||||
|
// TODO load the assembly from the common folder if the file exists (this would allow shared libraries)
|
||||||
string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
|
string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
|
||||||
if (assemblyPath != null)
|
if (assemblyPath != null)
|
||||||
return LoadFromAssemblyPath(assemblyPath);
|
return LoadFromAssemblyPath(assemblyPath);
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
|
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<SpaRoot>../Kyoo.WebApp/</SpaRoot>
|
<SpaRoot>../Kyoo.WebApp/</SpaRoot>
|
||||||
<LoginRoot>../Kyoo.WebLogin/</LoginRoot>
|
|
||||||
<TranscoderRoot>../Kyoo.Transcoder/</TranscoderRoot>
|
<TranscoderRoot>../Kyoo.Transcoder/</TranscoderRoot>
|
||||||
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules/**</DefaultItemExcludes>
|
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules/**</DefaultItemExcludes>
|
||||||
|
|
||||||
@ -52,7 +51,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules/**" Visible="false" />
|
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules/**" Visible="false" />
|
||||||
<StaticFiles Include="$(SpaRoot)static/**" Visible="false" />
|
<StaticFiles Include="$(SpaRoot)static/**" Visible="false" />
|
||||||
<LoginFiles Include="$(LoginRoot)**" Visible="false" />
|
|
||||||
<Content Remove="$(SpaRoot)**" />
|
<Content Remove="$(SpaRoot)**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@ -72,18 +70,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="Publish static and login" AfterTargets="ComputeFilesToPublish">
|
<Target Name="Publish static files" AfterTargets="ComputeFilesToPublish">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResolvedFileToPublish Include="@(StaticFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
|
<ResolvedFileToPublish Include="@(StaticFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
|
||||||
<RelativePath>wwwroot/%(StaticFiles.RecursiveDir)%(StaticFiles.Filename)%(StaticFiles.Extension)</RelativePath>
|
<RelativePath>wwwroot/%(StaticFiles.RecursiveDir)%(StaticFiles.Filename)%(StaticFiles.Extension)</RelativePath>
|
||||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||||
</ResolvedFileToPublish>
|
</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>
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
@ -91,9 +84,8 @@
|
|||||||
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
|
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
|
||||||
</Target>
|
</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="@(StaticFiles)" DestinationFolder="$(OutputPath)/wwwroot/%(RecursiveDir)" />
|
||||||
<Copy SourceFiles="@(LoginFiles)" DestinationFolder="$(OutputPath)/wwwroot/login/%(RecursiveDir)" />
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="Symlink views to output - Linux" AfterTargets="Build" Condition="$(Configuration) == 'Debug' And $(OS) == 'Unix'">
|
<Target Name="Symlink views to output - Linux" AfterTargets="Build" Condition="$(Configuration) == 'Debug' And $(OS) == 'Unix'">
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Kyoo.Authentication;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Kyoo.Postgresql;
|
using Kyoo.Postgresql;
|
||||||
@ -46,7 +47,11 @@ namespace Kyoo
|
|||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_plugins = new PluginManager(hostProvider, _configuration, loggerFactory.CreateLogger<PluginManager>());
|
_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>
|
/// <summary>
|
||||||
@ -55,7 +60,7 @@ namespace Kyoo
|
|||||||
/// <param name="services">The service collection to fill.</param>
|
/// <param name="services">The service collection to fill.</param>
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
string publicUrl = _configuration.GetValue<string>("public_url");
|
string publicUrl = _configuration.GetValue<string>("publicUrl");
|
||||||
|
|
||||||
services.AddMvc().AddControllersAsServices();
|
services.AddMvc().AddControllersAsServices();
|
||||||
|
|
||||||
@ -100,7 +105,6 @@ namespace Kyoo
|
|||||||
|
|
||||||
FileExtensionContentTypeProvider contentTypeProvider = new();
|
FileExtensionContentTypeProvider contentTypeProvider = new();
|
||||||
contentTypeProvider.Mappings[".data"] = "application/octet-stream";
|
contentTypeProvider.Mappings[".data"] = "application/octet-stream";
|
||||||
app.UseDefaultFiles();
|
|
||||||
app.UseStaticFiles(new StaticFileOptions
|
app.UseStaticFiles(new StaticFileOptions
|
||||||
{
|
{
|
||||||
ContentTypeProvider = contentTypeProvider,
|
ContentTypeProvider = contentTypeProvider,
|
||||||
|
@ -25,7 +25,7 @@ namespace Kyoo.Api
|
|||||||
public LibraryItemApi(ILibraryItemRepository libraryItems, IConfiguration configuration)
|
public LibraryItemApi(ILibraryItemRepository libraryItems, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_libraryItems = libraryItems;
|
_libraryItems = libraryItems;
|
||||||
_baseURL = configuration.GetValue<string>("public_url").TrimEnd('/');
|
_baseURL = configuration.GetValue<string>("publicUrl").TrimEnd('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"server.urls": "http://*:5000",
|
"server.urls": "http://*:5000",
|
||||||
"public_url": "http://localhost:5000/",
|
"publicUrl": "http://localhost:5000/",
|
||||||
|
|
||||||
"database": {
|
"database": {
|
||||||
"postgres": {
|
"postgres": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user