mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 13:14:29 -04:00
Remove the weird configuration options, add ApiKeys configuration
This commit is contained in:
parent
4d0dd674ad
commit
bf281820b9
13
.env.example
13
.env.example
@ -1,9 +1,20 @@
|
|||||||
# Useful config options
|
# Useful config options
|
||||||
LIBRARY_ROOT=/video
|
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=
|
TVDB__APIKEY=
|
||||||
THEMOVIEDB_APIKEY=
|
THEMOVIEDB_APIKEY=
|
||||||
PUBLIC_BACK_URL=http://localhost:5000
|
PUBLIC_BACK_URL=http://localhost:5000
|
||||||
AUTHENTICATION_SECRET=
|
|
||||||
|
|
||||||
|
|
||||||
# Following options are optional and only useful for debugging.
|
# Following options are optional and only useful for debugging.
|
||||||
|
|
||||||
|
@ -39,15 +39,6 @@ namespace Kyoo.Abstractions.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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, <see cref="Dictionary{TKey,TValue}"/> or <c>null</c>
|
|
||||||
/// can be specified.
|
|
||||||
/// </summary>
|
|
||||||
Dictionary<string, Type> Configuration { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An optional configuration step to allow a plugin to change asp net configurations.
|
/// An optional configuration step to allow a plugin to change asp net configurations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
@ -38,13 +37,6 @@ namespace Kyoo.Authentication
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Name => "Authentication";
|
public string Name => "Authentication";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Dictionary<string, Type> Configuration => new()
|
|
||||||
{
|
|
||||||
{ AuthenticationOption.Path, typeof(AuthenticationOption) },
|
|
||||||
{ PermissionOption.Path, typeof(PermissionOption) },
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The configuration to use.
|
/// The configuration to use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -69,9 +61,17 @@ namespace Kyoo.Authentication
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Configure(IServiceCollection services)
|
public void Configure(IServiceCollection services)
|
||||||
{
|
{
|
||||||
AuthenticationOption jwt = ConfigurationBinder.Get<AuthenticationOption>(
|
string secret = _configuration.GetValue("AUTHENTICATION_SECRET", AuthenticationOption.DefaultSecret);
|
||||||
_configuration.GetSection(AuthenticationOption.Path)
|
services.Configure<AuthenticationOption>(x =>
|
||||||
);
|
{
|
||||||
|
x.Secret = secret;
|
||||||
|
x.Permissions = new PermissionOption
|
||||||
|
{
|
||||||
|
Default = _configuration.GetValue<string>("UNLOGGED_PERMISSIONS", "overall.read").Split(','),
|
||||||
|
NewUser = _configuration.GetValue<string>("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)
|
// TODO handle direct-videos with bearers (probably add a cookie and a app.Use to translate that for videos)
|
||||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
@ -83,7 +83,7 @@ namespace Kyoo.Authentication
|
|||||||
ValidateAudience = false,
|
ValidateAudience = false,
|
||||||
ValidateLifetime = true,
|
ValidateLifetime = true,
|
||||||
ValidateIssuerSigningKey = true,
|
ValidateIssuerSigningKey = true,
|
||||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwt.Secret))
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secret))
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,5 @@ namespace Kyoo.Authentication.Models
|
|||||||
/// Options for permissions
|
/// Options for permissions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PermissionOption Permissions { get; set; } = new();
|
public PermissionOption Permissions { get; set; } = new();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Root path of user's profile pictures.
|
|
||||||
/// </summary>
|
|
||||||
public string ProfilePicturePath { get; set; } = "users/";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,11 +49,16 @@ namespace Kyoo.Authentication.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The default permissions that will be given to a non-connected user.
|
/// The default permissions that will be given to a non-connected user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] Default { get; set; } = new[] { "overall.read" };
|
public string[] Default { get; set; } = { "overall.read" };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Permissions applied to a new user.
|
/// Permissions applied to a new user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] NewUser { get; set; } = new[] { "overall.read" };
|
public string[] NewUser { get; set; } = { "overall.read" };
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The list of available ApiKeys.
|
||||||
|
/// </summary>
|
||||||
|
public string[] ApiKeys { get; set; } = Array.Empty<string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,12 +42,6 @@ namespace Kyoo.Core
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Name => "Core";
|
public string Name => "Core";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Dictionary<string, Type> Configuration => new()
|
|
||||||
{
|
|
||||||
{ "database", null },
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Configure(ContainerBuilder builder)
|
public void Configure(ContainerBuilder builder)
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using Autofac.Extras.AttributeMetadata;
|
using Autofac.Extras.AttributeMetadata;
|
||||||
@ -24,6 +23,8 @@ using Kyoo.Abstractions.Controllers;
|
|||||||
using Kyoo.Core.Models.Options;
|
using Kyoo.Core.Models.Options;
|
||||||
using Kyoo.Host.Controllers;
|
using Kyoo.Host.Controllers;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace Kyoo.Host
|
namespace Kyoo.Host
|
||||||
@ -36,24 +37,25 @@ namespace Kyoo.Host
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Name => "Host";
|
public string Name => "Host";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Dictionary<string, Type> Configuration => new()
|
|
||||||
{
|
|
||||||
{ BasicOptions.Path, typeof(BasicOptions) },
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The plugin manager that loaded all plugins.
|
/// The plugin manager that loaded all plugins.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IPluginManager _plugins;
|
private readonly IPluginManager _plugins;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The configuration used to register options.
|
||||||
|
/// </summary>
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new <see cref="HostModule"/>.
|
/// Create a new <see cref="HostModule"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="plugins">The plugin manager that loaded all plugins.</param>
|
/// <param name="plugins">The plugin manager that loaded all plugins.</param>
|
||||||
public HostModule(IPluginManager plugins)
|
/// <param name="configuration"> The configuration used to register options.</param>
|
||||||
|
public HostModule(IPluginManager plugins, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_plugins = plugins;
|
_plugins = plugins;
|
||||||
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -64,6 +66,12 @@ namespace Kyoo.Host
|
|||||||
builder.RegisterComposite<FileSystemComposite, IFileSystem>().InstancePerLifetimeScope();
|
builder.RegisterComposite<FileSystemComposite, IFileSystem>().InstancePerLifetimeScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Configure(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.Configure<BasicOptions>(_configuration.GetSection(BasicOptions.Path));
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerable<IStartupAction> ConfigureSteps => new[]
|
public IEnumerable<IStartupAction> ConfigureSteps => new[]
|
||||||
{
|
{
|
||||||
|
@ -112,20 +112,6 @@ namespace Kyoo.Host
|
|||||||
_hostModule.Configure(services);
|
_hostModule.Configure(services);
|
||||||
foreach (IPlugin plugin in _plugins.GetAllPlugins())
|
foreach (IPlugin plugin in _plugins.GetAllPlugins())
|
||||||
plugin.Configure(services);
|
plugin.Configure(services);
|
||||||
|
|
||||||
IEnumerable<KeyValuePair<string, Type>> configTypes = _plugins.GetAllPlugins()
|
|
||||||
.Append(_hostModule)
|
|
||||||
.SelectMany(x => x.Configuration)
|
|
||||||
.Where(x => x.Value != null);
|
|
||||||
foreach ((string path, Type type) in configTypes)
|
|
||||||
{
|
|
||||||
Utility.RunGenericMethod<object>(
|
|
||||||
typeof(OptionsConfigurationServiceCollectionExtensions),
|
|
||||||
nameof(OptionsConfigurationServiceCollectionExtensions.Configure),
|
|
||||||
type,
|
|
||||||
services, _configuration.GetSection(path)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"basics": {
|
|
||||||
"transmuxPath": "cached/transmux",
|
|
||||||
"transcodePath": "cached/transcode",
|
|
||||||
"metadataPath": "metadata/"
|
|
||||||
},
|
|
||||||
|
|
||||||
"authentication": {
|
|
||||||
"permissions": {
|
|
||||||
"default": ["overall.read", "overall.write"],
|
|
||||||
"newUser": ["overall.read", "overall.write"]
|
|
||||||
},
|
|
||||||
"profilePicturePath": "users/",
|
|
||||||
"secret": "4c@mraGB!KRfF@kpS8740y9FcHemKxBsqqxLbdR?"
|
|
||||||
}
|
|
||||||
}
|
|
@ -37,9 +37,6 @@ namespace Kyoo.Postgresql
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Name => "Postgresql";
|
public string Name => "Postgresql";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Dictionary<string, Type> Configuration => new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The configuration to use. The database connection string is pulled from it.
|
/// The configuration to use. The database connection string is pulled from it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -40,9 +40,6 @@ namespace Kyoo.Swagger
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string Name => "Swagger";
|
public string Name => "Swagger";
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Dictionary<string, Type> Configuration => new();
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Configure(IServiceCollection services)
|
public void Configure(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user