You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.8 KiB
42 lines
1.8 KiB
10 months ago
|
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<ApplicationDbContext>();
|
||
|
await context.Database.EnsureCreatedAsync(cancellationToken);
|
||
|
|
||
|
var manager = scope.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>();
|
||
|
//var authManager = scope.ServiceProvider.GetRequiredService<IOpenIddictAuthorizationManager>();
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|