Files
yavsc/src/Yavsc/Services/ClientStore.cs
Paul Schneider b4d9bd502d Find the client
2025-07-30 15:45:50 +01:00

38 lines
1.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
using IdentityServer8.Stores;
using IdentityServer8.Models;
namespace Yavsc.Services;
public class ClientStore : IClientStore
{
public ClientStore(ApplicationDbContext applicationDbContext)
{
ApplicationDbContext = applicationDbContext;
}
public ApplicationDbContext ApplicationDbContext { get; }
public async Task<Client> FindClientByIdAsync(string clientId)
{
var clientFromDb = await ApplicationDbContext.Client.FirstOrDefaultAsync(c => c.Id == clientId);
if (clientFromDb == null) return null;
return new Client
{
ClientId = clientFromDb.Id,
ClientName = clientFromDb.DisplayName,
ClientSecrets = { new Secret(clientFromDb.Secret.Sha256()) },
AllowedGrantTypes =
[
GrantType.AuthorizationCode,
GrantType.DeviceFlow,
GrantType.ClientCredentials
],
AllowedScopes = ["openid", "profile", "scope1"],
AbsoluteRefreshTokenLifetime = clientFromDb.RefreshTokenLifeTime,
AccessTokenLifetime = clientFromDb.AccessTokenLifetime
};
}
}