public async Task <AddClientPayload> AddClientAsync( AddClientInput input, [ScopedService] AppDbContext context, [Service] ITopicEventSender eventSender, CancellationToken cancellationToken) { var client = new Client { FirstName = input.FirstName, MiddleName = input.MiddleName, LastName = input.LastName, Email = input.Email, ProfileId = input.ProfileId }; context.Clients.Add(client); await context.SaveChangesAsync(cancellationToken); await eventSender.SendAsync(nameof(Subscription.OnClientAdded), client, cancellationToken); return(new AddClientPayload(client)); }
public async Task <AddClientOutput> AddClient(AddClientInput input) { if (!Regular.IsMatchLettersNumbers(input.ClientId)) { return(new AddClientOutput() { ErrorMessage = "客户端Id只能输入数字和字母" }); } if (!Regular.IsMatchLettersNumbers(input.ClientSecret)) { return(new AddClientOutput() { ErrorMessage = "密匙只能输入数字和字母" }); } var client = _clientManager.CreateClient(input.ClientId, input.AllowedGrantType, new List <string>() { input.ClientSecret }, input.RedirectUris, input.PostLogoutRedirectUris, input.AllowedScopes); client.ClientName = input.ClientName; client.AllowOfflineAccess = input.AllowOfflineAccess; client.AccessTokenType = (int)("jwt".Equals(input.AccessTokenType, StringComparison.OrdinalIgnoreCase) ? IdentityServer4.Models.AccessTokenType.Jwt: IdentityServer4.Models.AccessTokenType.Reference); client.AllowAccessTokensViaBrowser = input.AllowAccessTokensViaBrowser; client.Enabled = input.Enabled; _clientManager.AddClient(client); return(new AddClientOutput()); }