38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Sozsoft.Mcp.Services;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace Sozsoft.Mcp.Data;
|
|
|
|
/// <summary>
|
|
/// Bilinen MCP istemcilerini (<see cref="McpConsts.OAuthClientId"/>,
|
|
/// <see cref="McpConsts.LocalOAuthClientId"/>) seed eder. Geri donus adresleri
|
|
/// <c>OpenIddict:Applications:{ClientId}:RedirectUris</c> ayarindadir; yeni bir saglayici eklemek
|
|
/// bu listeye callback eklemektir. Ayari olmayan istemci olusturulmaz.
|
|
/// </summary>
|
|
public class McpOAuthClientDataSeedContributor(
|
|
IConfiguration configuration,
|
|
IMcpOAuthClientManager clientManager) : IDataSeedContributor, ITransientDependency
|
|
{
|
|
public async Task SeedAsync(DataSeedContext context)
|
|
{
|
|
// OpenIddict uygulamalari host kapsamindadir; kiraci seed turlarinda tekrarlanmaz.
|
|
if (context.TenantId is not null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var clientId in new[] { McpConsts.OAuthClientId, McpConsts.LocalOAuthClientId })
|
|
{
|
|
var redirectUris = configuration.GetSection($"OpenIddict:Applications:{clientId}:RedirectUris").Get<string[]>();
|
|
if (redirectUris is null || redirectUris.Length == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
await clientManager.EnsureKnownClientAsync(clientId, redirectUris);
|
|
}
|
|
}
|
|
}
|