public async Task Test_Create_IdentityServerUser_Add_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"
            };
            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());
        }
Пример #2
0
        public async Task <ActionResult> New(ClientViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Client client = new Client()
            {
                AccessTokenType = model.AccessTokenType,
                Enabled         = model.Enabled,
                AllowedScopes   = model.AllowedScopes,
                ClientId        = model.ClientId,
                ClientName      = model.ClientName,
                ClientSecrets   = model.ClientSecrets,
                Flow            = model.Flow
            };
            var adminStore = new IdentityServer3AdminStore();
            await adminStore.CreateClientAsync(client);

            var clients = new List <string> {
                client.ClientId
            };
            await adminStore.AddClientIdToIdentityServerUserAsync(User.Identity.GetUserId(), clients);

            return(RedirectToAction("Index"));
        }
        public async Task Test_Add_ClientIds_To_NonExisting_User_Async()
        {
            var userId     = Guid.NewGuid().ToString();
            var adminStore = new IdentityServer3AdminStore();

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

            Assert.IsFalse(appliedInfo.Applied);
            Assert.IsNotNull(appliedInfo.Exception);
            Assert.IsNotNull(appliedInfo.Exception as UserDoesNotExitException);
        }
        public async Task Test_Create_And_Delete_IdentityServerUserAsync()
        {
            var userId     = Guid.NewGuid().ToString();
            var adminStore = new IdentityServer3AdminStore();
            var user       = new IdentityServerUser {
                Enabled = true, UserId = userId, UserName = "******" + userId
            };

            var appliedInfo = await adminStore.CreateIdentityServerUserAsync(user);

            Assert.IsTrue(appliedInfo.Applied);
            Assert.IsNull(appliedInfo.Exception);
            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> scopesToAdd = new List <string> {
                "scope1", "scope2", "scope3", "scope4"
            };
            await adminStore.AddScopesToIdentityServerUserAsync(userId, scopesToAdd);

            var scopes = await adminStore.FindScopesByUserAsync(userId);

            Assert.AreEqual(scopes.Count(), scopesToAdd.Count);
            finalList = scopes.ToList().Except(scopesToAdd);
            Assert.IsFalse(finalList.Any());

            appliedInfo = await adminStore.DeleteIdentityServerUserAsync(userId);

            Assert.IsTrue(appliedInfo.Applied);
            Assert.IsNull(appliedInfo.Exception);
            result = await adminStore.FindIdentityServerUserByUserIdAsync(userId);

            Assert.IsNull(result);
        }
Пример #5
0
        public async Task <ActionResult> Manage(ClientViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var adminStore = new IdentityServer3AdminStore();
            var client     = await adminStore.FindClientByIdAsync(model.ClientId);

            client.ClientName = model.ClientName;
            client.Enabled    = model.Enabled;

            await adminStore.CreateClientAsync(client);

            var clients = new List <string> {
                client.ClientId
            };
            await adminStore.AddClientIdToIdentityServerUserAsync(User.Identity.GetUserId(), clients);

            return(RedirectToAction("Index"));
        }