diff --git a/.env.example b/.env.example
index c318972c..19aa2195 100644
--- a/.env.example
+++ b/.env.example
@@ -1,9 +1,20 @@
# Useful config options
LIBRARY_ROOT=/video
+
+# The following two values should be set to a random sequence of characters.
+# You MUST change thoses when installing kyoo (for security)
+AUTHENTICATION_SECRET=4c@mraGB!KRfF@kpS8739y9FcHemKxBsqqxLbdR?
+# You can input multiple api keys separated by a ,
+KYOO_APIKEYS=t7H5!@4iMNsAaSJQ49pat4jprJgTcF656if#J3
+
+DEFAULT_PERMISSIONS=overall.read
+UNLOGGED_PERMISSIONS=overall.read
+
TVDB__APIKEY=
THEMOVIEDB_APIKEY=
PUBLIC_BACK_URL=http://localhost:5000
-AUTHENTICATION_SECRET=
+
+
# Following options are optional and only useful for debugging.
diff --git a/back/src/Kyoo.Abstractions/Controllers/IPlugin.cs b/back/src/Kyoo.Abstractions/Controllers/IPlugin.cs
index a61d7b50..5c1e1442 100644
--- a/back/src/Kyoo.Abstractions/Controllers/IPlugin.cs
+++ b/back/src/Kyoo.Abstractions/Controllers/IPlugin.cs
@@ -39,15 +39,6 @@ namespace Kyoo.Abstractions.Controllers
///
string Name { get; }
- ///
- /// A list of types that will be available via the IOptions interfaces and will be listed inside
- /// an IConfiguration.
- ///
- /// If a field should be loosely typed, or null
- /// can be specified.
- ///
- Dictionary Configuration { get; }
-
///
/// An optional configuration step to allow a plugin to change asp net configurations.
///
diff --git a/back/src/Kyoo.Authentication/AuthenticationModule.cs b/back/src/Kyoo.Authentication/AuthenticationModule.cs
index bbbec812..8d32898f 100644
--- a/back/src/Kyoo.Authentication/AuthenticationModule.cs
+++ b/back/src/Kyoo.Authentication/AuthenticationModule.cs
@@ -16,7 +16,6 @@
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see .
-using System;
using System.Collections.Generic;
using System.Text;
using Autofac;
@@ -38,13 +37,6 @@ namespace Kyoo.Authentication
///
public string Name => "Authentication";
- ///
- public Dictionary Configuration => new()
- {
- { AuthenticationOption.Path, typeof(AuthenticationOption) },
- { PermissionOption.Path, typeof(PermissionOption) },
- };
-
///
/// The configuration to use.
///
@@ -69,9 +61,17 @@ namespace Kyoo.Authentication
///
public void Configure(IServiceCollection services)
{
- AuthenticationOption jwt = ConfigurationBinder.Get(
- _configuration.GetSection(AuthenticationOption.Path)
- );
+ string secret = _configuration.GetValue("AUTHENTICATION_SECRET", AuthenticationOption.DefaultSecret);
+ services.Configure(x =>
+ {
+ x.Secret = secret;
+ x.Permissions = new PermissionOption
+ {
+ Default = _configuration.GetValue("UNLOGGED_PERMISSIONS", "overall.read").Split(','),
+ NewUser = _configuration.GetValue("DEFAULT_PERMISSIONS", "overall.read").Split(','),
+ ApiKeys = _configuration.GetValue("KYOO_APIKEYS", string.Empty).Split(','),
+ };
+ });
// TODO handle direct-videos with bearers (probably add a cookie and a app.Use to translate that for videos)
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
@@ -83,7 +83,7 @@ namespace Kyoo.Authentication
ValidateAudience = false,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
- IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwt.Secret))
+ IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secret))
};
});
}
diff --git a/back/src/Kyoo.Authentication/Models/Options/AuthenticationOption.cs b/back/src/Kyoo.Authentication/Models/Options/AuthenticationOption.cs
index b57ed640..a5f22d75 100644
--- a/back/src/Kyoo.Authentication/Models/Options/AuthenticationOption.cs
+++ b/back/src/Kyoo.Authentication/Models/Options/AuthenticationOption.cs
@@ -42,10 +42,5 @@ namespace Kyoo.Authentication.Models
/// Options for permissions
///
public PermissionOption Permissions { get; set; } = new();
-
- ///
- /// Root path of user's profile pictures.
- ///
- public string ProfilePicturePath { get; set; } = "users/";
}
}
diff --git a/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs b/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs
index c7654465..3c585b9c 100644
--- a/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs
+++ b/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs
@@ -49,11 +49,16 @@ namespace Kyoo.Authentication.Models
///
/// The default permissions that will be given to a non-connected user.
///
- public string[] Default { get; set; } = new[] { "overall.read" };
+ public string[] Default { get; set; } = { "overall.read" };
///
/// Permissions applied to a new user.
///
- public string[] NewUser { get; set; } = new[] { "overall.read" };
+ public string[] NewUser { get; set; } = { "overall.read" };
+
+ ///
+ /// The list of available ApiKeys.
+ ///
+ public string[] ApiKeys { get; set; } = Array.Empty();
}
}
diff --git a/back/src/Kyoo.Core/CoreModule.cs b/back/src/Kyoo.Core/CoreModule.cs
index eaac6cc1..5e808c9a 100644
--- a/back/src/Kyoo.Core/CoreModule.cs
+++ b/back/src/Kyoo.Core/CoreModule.cs
@@ -42,12 +42,6 @@ namespace Kyoo.Core
///
public string Name => "Core";
- ///
- public Dictionary Configuration => new()
- {
- { "database", null },
- };
-
///
public void Configure(ContainerBuilder builder)
{
diff --git a/back/src/Kyoo.Host/HostModule.cs b/back/src/Kyoo.Host/HostModule.cs
index 6bbadf16..061370f3 100644
--- a/back/src/Kyoo.Host/HostModule.cs
+++ b/back/src/Kyoo.Host/HostModule.cs
@@ -16,7 +16,6 @@
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see .
-using System;
using System.Collections.Generic;
using Autofac;
using Autofac.Extras.AttributeMetadata;
@@ -24,6 +23,8 @@ using Kyoo.Abstractions.Controllers;
using Kyoo.Core.Models.Options;
using Kyoo.Host.Controllers;
using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
using Serilog;
namespace Kyoo.Host
@@ -36,24 +37,25 @@ namespace Kyoo.Host
///
public string Name => "Host";
- ///
- public Dictionary Configuration => new()
- {
- { BasicOptions.Path, typeof(BasicOptions) },
- };
-
///
/// The plugin manager that loaded all plugins.
///
private readonly IPluginManager _plugins;
+ ///
+ /// The configuration used to register options.
+ ///
+ private readonly IConfiguration _configuration;
+
///
/// Create a new .
///
/// The plugin manager that loaded all plugins.
- public HostModule(IPluginManager plugins)
+ /// The configuration used to register options.
+ public HostModule(IPluginManager plugins, IConfiguration configuration)
{
_plugins = plugins;
+ _configuration = configuration;
}
///
@@ -64,6 +66,12 @@ namespace Kyoo.Host
builder.RegisterComposite().InstancePerLifetimeScope();
}
+ ///
+ public void Configure(IServiceCollection services)
+ {
+ services.Configure(_configuration.GetSection(BasicOptions.Path));
+ }
+
///
public IEnumerable ConfigureSteps => new[]
{
diff --git a/back/src/Kyoo.Host/PluginsStartup.cs b/back/src/Kyoo.Host/PluginsStartup.cs
index ba06f9c6..f5c58f78 100644
--- a/back/src/Kyoo.Host/PluginsStartup.cs
+++ b/back/src/Kyoo.Host/PluginsStartup.cs
@@ -112,20 +112,6 @@ namespace Kyoo.Host
_hostModule.Configure(services);
foreach (IPlugin plugin in _plugins.GetAllPlugins())
plugin.Configure(services);
-
- IEnumerable> configTypes = _plugins.GetAllPlugins()
- .Append(_hostModule)
- .SelectMany(x => x.Configuration)
- .Where(x => x.Value != null);
- foreach ((string path, Type type) in configTypes)
- {
- Utility.RunGenericMethod