mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -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":
|
||||
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;
|
||||
|
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 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<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