mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 07:28:45 -07:00
Migrate server auth to IdentityServer
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using DorkNet.Models.Notification;
|
||||
using DorkNet.Server.Auth;
|
||||
using DorkNet.Server.Data;
|
||||
@@ -39,6 +40,8 @@ public class AdminController(
|
||||
SignupCodeService signupCodes,
|
||||
IObjectStorage storage,
|
||||
DomainConfig domain,
|
||||
IConfiguration config,
|
||||
IdentityServerSigningKeyProvider signingKeys,
|
||||
ILogger<AdminController> adminLogger) : ControllerBase
|
||||
{
|
||||
private long CurrentAdminId => this.RequireCurrentPlayerId();
|
||||
@@ -1159,6 +1162,63 @@ public class AdminController(
|
||||
|
||||
// ── Server settings (runtime toggles) ────────────────────────────────
|
||||
|
||||
[HttpGet("identityserver")]
|
||||
public ActionResult GetIdentityServerSettings()
|
||||
{
|
||||
var issuer = domain.AuthIssuer.TrimEnd('/');
|
||||
var client = RecRoomIdentityServerConfig.Clients[0];
|
||||
var certPath = signingKeys.CertificatePath;
|
||||
var fullCertPath = Path.GetFullPath(certPath);
|
||||
var licenseConfigured =
|
||||
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("DUENDE_IDENTITYSERVER_LICENSE_KEY"))
|
||||
|| !string.IsNullOrWhiteSpace(config["IdentityServer:LicenseKey"]);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
Issuer = issuer,
|
||||
DiscoveryUrl = $"{issuer}/.well-known/openid-configuration",
|
||||
TokenEndpoint = $"{issuer}/connect/token",
|
||||
UserInfoEndpoint = $"{issuer}/connect/userinfo",
|
||||
Client = new
|
||||
{
|
||||
client.ClientId,
|
||||
client.ClientName,
|
||||
AllowedGrantTypes = client.AllowedGrantTypes.ToArray(),
|
||||
AllowedScopes = client.AllowedScopes.ToArray(),
|
||||
client.AllowOfflineAccess,
|
||||
client.AccessTokenLifetime,
|
||||
client.AbsoluteRefreshTokenLifetime,
|
||||
client.SlidingRefreshTokenLifetime,
|
||||
RefreshTokenUsage = client.RefreshTokenUsage.ToString(),
|
||||
RefreshTokenExpiration = client.RefreshTokenExpiration.ToString(),
|
||||
},
|
||||
Signing = new
|
||||
{
|
||||
CertificatePath = fullCertPath,
|
||||
CertificateExists = System.IO.File.Exists(fullCertPath),
|
||||
signingKeys.Certificate.Thumbprint,
|
||||
NotBeforeUtc = signingKeys.Certificate.NotBefore.ToUniversalTime(),
|
||||
NotAfterUtc = signingKeys.Certificate.NotAfter.ToUniversalTime(),
|
||||
Algorithm = SecurityAlgorithms.RsaSha256,
|
||||
},
|
||||
License = new
|
||||
{
|
||||
Configured = licenseConfigured,
|
||||
},
|
||||
PersistedGrants = new
|
||||
{
|
||||
Store = "in-memory",
|
||||
Warning = "Refresh tokens are process-local until an operational store is configured.",
|
||||
},
|
||||
LegacyCompatibility = new
|
||||
{
|
||||
InjectsClientId = true,
|
||||
InjectsDefaultScopes = true,
|
||||
AddsLegacyTokenAliases = true,
|
||||
AcceptsLegacyJwtSigningKey = true,
|
||||
},
|
||||
});
|
||||
}
|
||||
/// <summary>GET <c>api/admin/v1/settings</c> — current server-wide
|
||||
/// toggle state. Single row, single round trip.</summary>
|
||||
[HttpGet("settings")]
|
||||
|
||||
Reference in New Issue
Block a user