mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Add info endpoint to list oidc providers names and logo
This commit is contained in:
parent
5827a18866
commit
5f8d0d1b99
@ -118,6 +118,12 @@ namespace Kyoo.Authentication
|
|||||||
case "profile":
|
case "profile":
|
||||||
acc[provider].ProfileUrl = val.Value;
|
acc[provider].ProfileUrl = val.Value;
|
||||||
break;
|
break;
|
||||||
|
case "name":
|
||||||
|
acc[provider].DisplayName = val.Value;
|
||||||
|
break;
|
||||||
|
case "logo":
|
||||||
|
acc[provider].LogoUrl = val.Value;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
logger.LogError("Invalid oidc config value: {Key}", key);
|
logger.LogError("Invalid oidc config value: {Key}", key);
|
||||||
return acc;
|
return acc;
|
||||||
|
32
back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs
Normal file
32
back/src/Kyoo.Authentication/Models/DTO/ServerInfo.cs
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Kyoo.Authentication.Models;
|
||||||
|
|
||||||
|
public class ServerInfo
|
||||||
|
{
|
||||||
|
public Dictionary<string, OidcInfo> Oidc { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OidcInfo
|
||||||
|
{
|
||||||
|
public string DisplayName { get; set; }
|
||||||
|
public string? LogoUrl { get; set; }
|
||||||
|
}
|
@ -63,12 +63,14 @@ public class PermissionOption
|
|||||||
|
|
||||||
public class OidcProvider
|
public class OidcProvider
|
||||||
{
|
{
|
||||||
|
public string DisplayName { get; set; }
|
||||||
|
public string? LogoUrl { get; set; }
|
||||||
public string AuthorizationUrl { get; set; }
|
public string AuthorizationUrl { get; set; }
|
||||||
public string TokenUrl { get; set; }
|
public string TokenUrl { get; set; }
|
||||||
public string ProfileUrl { get; set; }
|
public string ProfileUrl { get; set; }
|
||||||
|
public string? Scope { get; set; }
|
||||||
public string ClientId { get; set; }
|
public string ClientId { get; set; }
|
||||||
public string Secret { get; set; }
|
public string Secret { get; set; }
|
||||||
public string? Scope { get; set; }
|
|
||||||
|
|
||||||
public bool Enabled =>
|
public bool Enabled =>
|
||||||
AuthorizationUrl != null
|
AuthorizationUrl != null
|
||||||
@ -79,16 +81,30 @@ public class OidcProvider
|
|||||||
|
|
||||||
public OidcProvider(string provider)
|
public OidcProvider(string provider)
|
||||||
{
|
{
|
||||||
switch (provider)
|
DisplayName = provider;
|
||||||
|
if (KnownProviders?.ContainsKey(provider) == true)
|
||||||
{
|
{
|
||||||
case "google":
|
DisplayName = KnownProviders[provider].DisplayName;
|
||||||
AuthorizationUrl = "https://accounts.google.com/o/oauth2/v2/auth";
|
LogoUrl = KnownProviders[provider].LogoUrl;
|
||||||
TokenUrl = "https://oauth2.googleapis.com/token";
|
AuthorizationUrl = KnownProviders[provider].AuthorizationUrl;
|
||||||
ProfileUrl = "https://openidconnect.googleapis.com/v1/userinfo";
|
TokenUrl = KnownProviders[provider].TokenUrl;
|
||||||
Scope = "email profile";
|
ProfileUrl = KnownProviders[provider].ProfileUrl;
|
||||||
break;
|
Scope = KnownProviders[provider].Scope;
|
||||||
default:
|
ClientId = KnownProviders[provider].ClientId;
|
||||||
break;
|
Secret = KnownProviders[provider].Secret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly Dictionary<string, OidcProvider> 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",
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
50
back/src/Kyoo.Authentication/Views/InfoApi.cs
Normal file
50
back/src/Kyoo.Authentication/Views/InfoApi.cs
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Info about the current instance
|
||||||
|
/// </summary>
|
||||||
|
[ApiController]
|
||||||
|
[Route("info")]
|
||||||
|
[ApiDefinition("Info", Group = UsersGroup)]
|
||||||
|
public class InfoApi(PermissionOption options) : ControllerBase
|
||||||
|
{
|
||||||
|
public ActionResult<ServerInfo> GetInfo()
|
||||||
|
{
|
||||||
|
return Ok(
|
||||||
|
new ServerInfo()
|
||||||
|
{
|
||||||
|
Oidc = options
|
||||||
|
.OIDC.Select(x => new KeyValuePair<string, OidcInfo>(
|
||||||
|
x.Key,
|
||||||
|
new() { DisplayName = x.Value.DisplayName, LogoUrl = x.Value.LogoUrl, }
|
||||||
|
))
|
||||||
|
.ToDictionary(x => x.Key, x => x.Value),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user