コード例 #1
0
        public async Task CreateAsync(Client client)
        {
            Ensure.That(client.Id == null, "Client Id is set internally when creating new clients");
            Ensure.NotNullOrEmpty(client.TenantKey);

            client.Id = KeyGen.NewGuid();

            // Initialize OIDC for this new client
            var tenant = await _tenantManager.CreateAsync(client.TenantKey, client.Name);

            var directory = await _directoryManager.CreateAsync(client.TenantKey, "Default User Directory");

            // create a new security pool mapped to the default directory
            var clientSecurityPool = await _poolManager.CreateTenantPoolAsync
                                     (
                client.TenantKey,
                client.Name + " Pool",
                new Identity.Models.Directory[] { directory }
                                     );

            // Create the Connect Client
            client.SecurityPoolId = clientSecurityPool.PoolId;

            if (client.AnniversaryDate == null)
            {
                client.AnniversaryDate = DateTime.UtcNow;
            }

            _db.Add(client);
            await _db.SaveChangesAsync();

            // Insert default roles
            await CreateDefaultClientLevelRoles(client);
        }