using OpenIddict.Abstractions; namespace HuiXin.Identity.OpenIddict { public class Worker : IHostedService { private readonly IServiceProvider _serviceProvider; public Worker(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider; public async Task StartAsync(CancellationToken cancellationToken) { using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); await context.Database.EnsureCreatedAsync(cancellationToken); var manager = scope.ServiceProvider.GetRequiredService(); //var authManager = scope.ServiceProvider.GetRequiredService(); var data = await manager.FindByClientIdAsync("apisix", cancellationToken) ?? await manager.CreateAsync( new OpenIddictApplicationDescriptor { ClientId = "apisix", ClientSecret = "388D45FA-B36B-4988-BA59-B187D329C207", DisplayName = "APISIX的测试客户", Permissions = { OpenIddictConstants.Permissions.Endpoints.Authorization, OpenIddictConstants.Permissions.Endpoints.Logout, OpenIddictConstants.Permissions.Endpoints.Token }, RedirectUris = { new Uri("http://8.134.191.93:9080/test/callback")}, }, cancellationToken); //await manager.DeleteAsync(data); Console.WriteLine($"APISIX的测试客户:{System.Text.Json.JsonSerializer.Serialize(data)}"); } public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; } }