Remove public url

This commit is contained in:
Zoe Roux 2022-06-12 19:13:16 +02:00
parent 9dd783fd2f
commit f6557e6bbc
No known key found for this signature in database
GPG Key ID: 54F19BB73170955D
12 changed files with 15 additions and 70 deletions

View File

@ -49,7 +49,6 @@ services:
restart: on-failure
environment:
- KYOO_DATADIR=/var/lib/kyoo
- BASICS__PUBLICURL=https://demo.kyoo.moe
- DATABASE__ENABLED=postgres
- DATABASE__CONFIGURATIONS__POSTGRES__SERVER=postgres
- DATABASE__CONFIGURATIONS__POSTGRES__USER ID=kyoo

View File

@ -6,7 +6,6 @@ services:
restart: on-failure
environment:
- KYOO_DATADIR=/var/lib/kyoo
- BASICS__PUBLICURL=http://localhost:5000
- DATABASE__ENABLED=postgres
- DATABASE__CONFIGURATIONS__POSTGRES__SERVER=postgres
- DATABASE__CONFIGURATIONS__POSTGRES__USER=kyoo

View File

@ -22,7 +22,6 @@ We are going to take a look at the fields you might want to change to tailor Kyo
- ```basics```
- ```url```: The port on which Kyoo will be exposed
- ```publicUrl```: The full URL for Kyoo.
For the 3 following fields, the path are relative to the directory ```settings.json``` is in
- ```pluginsPath```: The directory where the plugins are stored
- ```transmuxPath```: The directory where the transmux-ed video are stored (used as a cache)
@ -34,7 +33,7 @@ We are going to take a look at the fields you might want to change to tailor Kyo
- ```tasks```
- ```parallels```: The number of tasks that can be run at the same time. If the values is not ```1```, the behavior is not implemented.
- ```scheduled```: An object with keys being the name of an automation task, with a value being the interval between each task of the same type.
- The available keys can be found at ```publicUrl/api/tasks``` (as 'slug')
- The available keys can be found at ```/api/tasks``` (as 'slug')
- The values must be formatted like ```HH:MM:SS``
**For Example** in the default configuration, a file scan task will be executed every 24 hours
@ -81,7 +80,7 @@ If everything looks normal, no error message will appear, just log messages.
Then, we are going to interact with Kyoo's API. To create a library, you must do the following request for each library you want to make:
- POST Request
- At ```publicUrl/api/libraries``` (```publicUrl``` is in ```settings.json```)
- At ```/api/libraries```
- Content-Type: ```application/json```
- Body:
@ -97,6 +96,6 @@ Then, we are going to interact with Kyoo's API. To create a library, you must do
}
```
Now that you created your libraries, you can do a simple GET request to ```publicUrl/api/task/scan``` to scan for videos in all the libraries.
Now that you created your libraries, you can do a simple GET request to ```/api/task/scan``` to scan for videos in all the libraries.
Once the scan is over, ```Task finished: Scan Libraries``` will be displayed! You are now ready to use Kyoo!

View File

@ -91,15 +91,5 @@ namespace Kyoo.Abstractions
{
return builder.RegisterRepository<T2>().As<T>();
}
/// <summary>
/// Get the public URL of kyoo using the given configuration instance.
/// </summary>
/// <param name="configuration">The configuration instance</param>
/// <returns>The public URl of kyoo (without a slash at the end)</returns>
public static Uri GetPublicUrl(this IConfiguration configuration)
{
return new Uri(configuration["basics:publicUrl"] ?? "http://localhost:5000");
}
}
}

View File

@ -20,7 +20,6 @@ using System;
using System.Collections.Generic;
using System.Text;
using Autofac;
using Kyoo.Abstractions;
using Kyoo.Abstractions.Controllers;
using Kyoo.Authentication.Models;
using Microsoft.AspNetCore.Authentication.JwtBearer;
@ -76,7 +75,6 @@ namespace Kyoo.Authentication
/// <inheritdoc />
public void Configure(IServiceCollection services)
{
Uri publicUrl = _configuration.GetPublicUrl();
AuthenticationOption jwt = ConfigurationBinder.Get<AuthenticationOption>(
_configuration.GetSection(AuthenticationOption.Path)
);
@ -87,12 +85,10 @@ namespace Kyoo.Authentication
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateIssuer = false,
ValidateAudience = false,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = publicUrl.ToString(),
ValidAudience = publicUrl.ToString(),
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwt.Secret))
};
});

View File

@ -24,10 +24,8 @@ using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Kyoo.Abstractions;
using Kyoo.Abstractions.Models;
using Kyoo.Authentication.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
@ -43,20 +41,13 @@ namespace Kyoo.Authentication
/// </summary>
private readonly IOptions<AuthenticationOption> _options;
/// <summary>
/// The configuration used to retrieve the public URL of kyoo.
/// </summary>
private readonly IConfiguration _configuration;
/// <summary>
/// Create a new <see cref="TokenController"/>.
/// </summary>
/// <param name="options">The options that this controller will use.</param>
/// <param name="configuration">The configuration used to retrieve the public URL of kyoo.</param>
public TokenController(IOptions<AuthenticationOption> options, IConfiguration configuration)
public TokenController(IOptions<AuthenticationOption> options)
{
_options = options;
_configuration = configuration;
}
/// <inheritdoc />
@ -80,8 +71,6 @@ namespace Kyoo.Authentication
claims.Add(new Claim(Claims.Email, user.Email));
JwtSecurityToken token = new(
signingCredentials: credential,
issuer: _configuration.GetPublicUrl().ToString(),
audience: _configuration.GetPublicUrl().ToString(),
claims: claims,
expires: DateTime.UtcNow.Add(expireIn)
);
@ -95,8 +84,6 @@ namespace Kyoo.Authentication
SigningCredentials credential = new(key, SecurityAlgorithms.HmacSha256Signature);
JwtSecurityToken token = new(
signingCredentials: credential,
issuer: _configuration.GetPublicUrl().ToString(),
audience: _configuration.GetPublicUrl().ToString(),
claims: new[]
{
new Claim(Claims.Id, user.ID.ToString(CultureInfo.InvariantCulture)),
@ -119,12 +106,10 @@ namespace Kyoo.Authentication
{
principal = tokenHandler.ValidateToken(refreshToken, new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateIssuer = false,
ValidateAudience = false,
ValidateIssuerSigningKey = true,
ValidateLifetime = true,
ValidIssuer = _configuration.GetPublicUrl().ToString(),
ValidAudience = _configuration.GetPublicUrl().ToString(),
IssuerSigningKey = key
}, out SecurityToken _);
}

View File

@ -16,8 +16,6 @@
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
using System;
namespace Kyoo.Core.Models.Options
{
/// <summary>
@ -35,11 +33,6 @@ namespace Kyoo.Core.Models.Options
/// </summary>
public string Url { get; set; } = "http://*:5000";
/// <summary>
/// The public url that will be used in items response and in authentication server host.
/// </summary>
public Uri PublicUrl { get; set; } = new("http://localhost:5000");
/// <summary>
/// The path of the plugin directory.
/// </summary>

View File

@ -45,12 +45,9 @@ namespace Kyoo.Core.Api
protected Page<TResult> Page<TResult>(ICollection<TResult> resources, int limit)
where TResult : IResource
{
Uri publicUrl = HttpContext.RequestServices
.GetRequiredService<IConfiguration>()
.GetPublicUrl();
return new Page<TResult>(
resources,
new Uri(publicUrl, Request.Path),
new Uri(Request.Path),
Request.Query.ToDictionary(
x => x.Key,
x => x.Value.ToString(),

View File

@ -107,7 +107,7 @@ namespace Kyoo.Core.Api
IThumbnails thumb = (IThumbnails)x;
return thumb?.Images?.ContainsKey(id) == true;
},
ValueProvider = new ThumbnailProvider(_options.Value.PublicUrl, id)
ValueProvider = new ThumbnailProvider(id)
});
}
@ -120,11 +120,6 @@ namespace Kyoo.Core.Api
/// </summary>
private class ThumbnailProvider : IValueProvider
{
/// <summary>
/// The public address of kyoo.
/// </summary>
private readonly Uri _host;
/// <summary>
/// The index/ID of the image to retrieve/set.
/// </summary>
@ -133,11 +128,9 @@ namespace Kyoo.Core.Api
/// <summary>
/// Create a new <see cref="ThumbnailProvider"/>.
/// </summary>
/// <param name="host">The public address of kyoo.</param>
/// <param name="imageIndex">The index/ID of the image to retrieve/set.</param>
public ThumbnailProvider(Uri host, int imageIndex)
public ThumbnailProvider(int imageIndex)
{
_host = host;
_imageIndex = imageIndex;
}
@ -160,7 +153,7 @@ namespace Kyoo.Core.Api
string type = target is ICustomTypeDescriptor descriptor
? descriptor.GetClassName()
: target.GetType().Name;
return new Uri(_host, $"/api/{type}/{slug}/{Images.ImageName[_imageIndex]}".ToLower())
return new Uri($"/api/{type}/{slug}/{Images.ImageName[_imageIndex]}".ToLowerInvariant())
.ToString();
}
}

View File

@ -1,7 +1,6 @@
{
"basics": {
"url": "http://*:5000",
"publicUrl": "http://localhost:5000/",
"pluginsPath": "plugins/",
"transmuxPath": "cached/transmux",
"transcodePath": "cached/transcode",

View File

@ -40,7 +40,7 @@ namespace Kyoo.Host.WindowsTrait
private readonly IApplication _application;
/// <summary>
/// The options containing the <see cref="BasicOptions.PublicUrl"/>.
/// The options containing the <see cref="BasicOptions.Url"/>.
/// </summary>
private readonly IOptions<BasicOptions> _options;
@ -90,7 +90,7 @@ namespace Kyoo.Host.WindowsTrait
private readonly IApplication _application;
/// <summary>
/// The options containing the <see cref="BasicOptions.PublicUrl"/>.
/// The options containing the <see cref="BasicOptions.Url"/>.
/// </summary>
private readonly IOptions<BasicOptions> _options;
@ -161,7 +161,7 @@ namespace Kyoo.Host.WindowsTrait
{
Process browser = new()
{
StartInfo = new ProcessStartInfo(_options.Value.PublicUrl.ToString())
StartInfo = new ProcessStartInfo(_options.Value.Url.ToString().Replace("//*:", "//localhost:"))
{
UseShellExecute = true
}

View File

@ -91,11 +91,6 @@ namespace Kyoo.Swagger
Name = "GPL-3.0-or-later",
Url = "https://github.com/AnonymusRaccoon/Kyoo/blob/master/LICENSE"
};
options.Servers.Add(new OpenApiServer
{
Url = _configuration.GetPublicUrl().ToString(),
Description = "The currently running kyoo's instance."
});
options.Info.ExtensionData ??= new Dictionary<string, object>();
options.Info.ExtensionData["x-logo"] = new