Example #1
0
        public async Task <ActionResult> Delete(ClientViewModel model)
        {
            var adminStore = new IdentityServer3AdminStore();
            await
            adminStore.DeleteClientIdsByUserIdAsync(User.Identity.GetUserId(), new List <string>() { model.ClientId });

            await adminStore.DeleteClientAsync(model.ClientId);

            return(RedirectToAction("Index"));
        }
        public async Task Test_Create_IdentityServerUser_Add_AND_Delete_ClientIds_Async()
        {
            var userId     = Guid.NewGuid().ToString();
            var adminStore = new IdentityServer3AdminStore();
            var user       = new IdentityServerUser {
                Enabled = true, UserId = userId, UserName = "******" + userId
            };

            await adminStore.CreateIdentityServerUserAsync(user);

            var result = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.AreEqual(user.UserId, result.UserId);

            List <string> clientIdsToAdd = new List <string> {
                "clientid1", "clientid2", "clientid3", "clientid4"
            };
            await adminStore.AddClientIdToIdentityServerUserAsync(userId, clientIdsToAdd);

            var clientIds = await adminStore.FindClientIdsByUserAsync(userId);

            Assert.AreEqual(clientIds.Count(), clientIdsToAdd.Count);
            var finalList = clientIds.ToList().Except(clientIdsToAdd);

            Assert.IsFalse(finalList.Any());


            List <string> clientsToDelete = new List <string> {
                "clientid1", "clientid2"
            };
            await adminStore.DeleteClientIdsByUserIdAsync(userId, clientsToDelete);

            clientIds = await adminStore.FindClientIdsByUserAsync(userId);

            var finalExpectedList = clientIdsToAdd.ToList().Except(clientsToDelete).ToList();

            Assert.AreEqual(clientIds.Count(), finalExpectedList.Count());
            finalList = clientIds.ToList().Except(finalExpectedList);
            Assert.IsFalse(finalList.Any());
        }