Пример #1
0
        public async Task <ActionResult> ManageScopes(ClientScopeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var adminStore = new IdentityServer3AdminStore();

            if (model.AllowedScopes != null)
            {
                // remove the ones that need to be removed
                var queryToBeDeleted = (from item in model.AllowedScopes
                                        where item.Enabled == false
                                        select item.Name).ToList();
                if (queryToBeDeleted.Any())
                {
                    await adminStore.DeleteScopesFromClientAsync(model.ClientId, queryToBeDeleted);
                }
            }
            if (model.UserScopes != null)
            {
                var queryToBeAdded = (from item in model.UserScopes
                                      where item.Enabled
                                      select item.Name).ToList();
                if (queryToBeAdded.Any())
                {
                    await adminStore.AddScopesToClientAsync(model.ClientId, queryToBeAdded);
                }
            }


            return(RedirectToAction("ManageScopes", new { clientId = model.ClientId }));
        }
Пример #2
0
        public async Task Test_Create_Add_ScopeByClientIdAsync()
        {
            var insert = await CassandraTestHelper.InsertTestData_Clients(1);

            var adminStore = new IdentityServer3AdminStore();
            // await adminStore.CleanupClientByIdAsync(insert[0].ClientId);
            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            var originalAllowedScopes = result.AllowedScopes;

            Assert.AreEqual(insert[0].ClientName, result.ClientName);

            List <Scope> scopes = new List <Scope>()
            {
                new Scope()
                {
                    AllowUnrestrictedIntrospection = true,
                    Name    = Guid.NewGuid().ToString(),
                    Enabled = true
                },
                new Scope()
                {
                    AllowUnrestrictedIntrospection = true,
                    Name    = Guid.NewGuid().ToString(),
                    Enabled = true
                }
            };

            foreach (var scope in scopes)
            {
                await adminStore.CreateScopeAsync(scope);
            }


            var query = from item in scopes
                        let c = item.Name
                                select c;

            List <string> addedScopeNames = query.ToList();
            List <string> finalExpected   = new List <string>();

            finalExpected.AddRange(addedScopeNames);
            finalExpected.AddRange(result.AllowedScopes);

            await adminStore.AddScopesToClientAsync(insert[0].ClientId, addedScopeNames);



            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.AllowedScopes.Count(), finalExpected.Count);


            var ff = result.AllowedScopes.Except(finalExpected);

            Assert.IsFalse(ff.Any());
        }