diff --git a/back/src/Kyoo.Authentication/AuthenticationModule.cs b/back/src/Kyoo.Authentication/AuthenticationModule.cs index 72bbfff5..fbe12c69 100644 --- a/back/src/Kyoo.Authentication/AuthenticationModule.cs +++ b/back/src/Kyoo.Authentication/AuthenticationModule.cs @@ -118,6 +118,12 @@ namespace Kyoo.Authentication case "profile": acc[provider].ProfileUrl = val.Value; break; + case "name": + acc[provider].DisplayName = val.Value; + break; + case "logo": + acc[provider].LogoUrl = val.Value; + break; default: logger.LogError("Invalid oidc config value: {Key}", key); return acc; diff --git a/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs b/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs new file mode 100644 index 00000000..866e3b18 --- /dev/null +++ b/back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs @@ -0,0 +1,32 @@ +// Kyoo - A portable and vast media library solution. +// Copyright (c) Kyoo. +// +// See AUTHORS.md and LICENSE file in the project root for full license information. +// +// Kyoo is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// Kyoo is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kyoo. If not, see . + +using System.Collections.Generic; + +namespace Kyoo.Authentication.Models; + +public class ServerInfo +{ + public Dictionary Oidc { get; set; } +} + +public class OidcInfo +{ + public string DisplayName { get; set; } + public string? LogoUrl { get; set; } +} diff --git a/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs b/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs index eb7205f2..1ae00412 100644 --- a/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs +++ b/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs @@ -63,12 +63,14 @@ public class PermissionOption public class OidcProvider { + public string DisplayName { get; set; } + public string? LogoUrl { get; set; } public string AuthorizationUrl { get; set; } public string TokenUrl { get; set; } public string ProfileUrl { get; set; } + public string? Scope { get; set; } public string ClientId { get; set; } public string Secret { get; set; } - public string? Scope { get; set; } public bool Enabled => AuthorizationUrl != null @@ -79,16 +81,30 @@ public class OidcProvider public OidcProvider(string provider) { - switch (provider) + DisplayName = provider; + if (KnownProviders?.ContainsKey(provider) == true) { - case "google": - AuthorizationUrl = "https://accounts.google.com/o/oauth2/v2/auth"; - TokenUrl = "https://oauth2.googleapis.com/token"; - ProfileUrl = "https://openidconnect.googleapis.com/v1/userinfo"; - Scope = "email profile"; - break; - default: - break; + DisplayName = KnownProviders[provider].DisplayName; + LogoUrl = KnownProviders[provider].LogoUrl; + AuthorizationUrl = KnownProviders[provider].AuthorizationUrl; + TokenUrl = KnownProviders[provider].TokenUrl; + ProfileUrl = KnownProviders[provider].ProfileUrl; + Scope = KnownProviders[provider].Scope; + ClientId = KnownProviders[provider].ClientId; + Secret = KnownProviders[provider].Secret; } } + + public static readonly Dictionary KnownProviders = new() + { + ["google"] = new("google") + { + DisplayName = "Google", + LogoUrl = "https://logo.clearbit.com/google.com", + AuthorizationUrl = "https://accounts.google.com/o/oauth2/v2/auth", + TokenUrl = "https://oauth2.googleapis.com/token", + ProfileUrl = "https://openidconnect.googleapis.com/v1/userinfo", + Scope = "email profile", + }, + }; } diff --git a/back/src/Kyoo.Authentication/Views/InfoApi.cs b/back/src/Kyoo.Authentication/Views/InfoApi.cs new file mode 100644 index 00000000..3972ac99 --- /dev/null +++ b/back/src/Kyoo.Authentication/Views/InfoApi.cs @@ -0,0 +1,50 @@ +// Kyoo - A portable and vast media library solution. +// Copyright (c) Kyoo. +// +// See AUTHORS.md and LICENSE file in the project root for full license information. +// +// Kyoo is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// Kyoo is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kyoo. If not, see . + +using System.Collections.Generic; +using System.Linq; +using Kyoo.Abstractions.Models.Attributes; +using Kyoo.Authentication.Models; +using Microsoft.AspNetCore.Mvc; +using static Kyoo.Abstractions.Models.Utils.Constants; + +namespace Kyoo.Authentication.Views; + +/// +/// Info about the current instance +/// +[ApiController] +[Route("info")] +[ApiDefinition("Info", Group = UsersGroup)] +public class InfoApi(PermissionOption options) : ControllerBase +{ + public ActionResult GetInfo() + { + return Ok( + new ServerInfo() + { + Oidc = options + .OIDC.Select(x => new KeyValuePair( + x.Key, + new() { DisplayName = x.Value.DisplayName, LogoUrl = x.Value.LogoUrl, } + )) + .ToDictionary(x => x.Key, x => x.Value), + } + ); + } +}