public async Task Test_Create_IdentityServerUser_Add_AllowedScopes_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> scopesToAdd = new List <string> {
                "scope1", "scope2"
            };
            await adminStore.AddScopesToIdentityServerUserAsync(userId, scopesToAdd);

            var scopes = await adminStore.FindScopesByUserAsync(userId);

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

            Assert.IsFalse(finalList.Any());
        }
        // GET: Admin/Home/Manage/5
        public async Task <ActionResult> Manage(string id, string email)
        {
            var fullUserStore = UserManager.FullUserStore;
            var claims        = await fullUserStore.GetClaimsAsync(Guid.Parse(id));

            var query = from item in claims
                        where item.Type == ClaimTypes.Role && item.Value == "Developer"
                        select item;

            var adminStore = new IdentityServer3AdminStore();

            ViewBag.Email = email;
            var exists = await adminStore.FindDoesUserExistByUserIdAsync(id);

            if (exists)
            {
                var scopes = await adminStore.FindScopesByUserAsync(id);
            }
            IdentityServerUserModel isum = new IdentityServerUserModel()
            {
                UserId        = id,
                Exists        = exists,
                AllowedScopes = new List <string>(),
                Developer     = query.Any()
            };

            return(View(isum));
        }
예제 #3
0
        public async Task <ActionResult> ManageScopes(string clientId)
        {
            var adminStore = new IdentityServer3AdminStore();
            var userScopes = await adminStore.FindScopesByUserAsync(User.Identity.GetUserId());

            var queryUserScopes = from item in userScopes
                                  let c = new ScopeEnabledRecord()
            {
                Enabled = false,
                Name    = item
            }
            select c;

            var currentClient = await adminStore.FindClientByIdAsync(clientId);

            var queryAllowedScopes = from item in currentClient.AllowedScopes
                                     let c = new ScopeEnabledRecord()
            {
                Enabled = true,
                Name    = item
            }
            select c;

            var model = new ClientScopeModel()
            {
                ClientId      = clientId,
                UserScopes    = queryUserScopes.ToList(),
                AllowedScopes = queryAllowedScopes.ToList()
            };

            return(View(model));
        }
        public async Task <IEnumerable <string> > GetUserScopesAsync( )
        {
            var adminStore = new IdentityServer3AdminStore();
            var userId     = User.Identity.GetUserId();
            var scopes     = await adminStore.FindScopesByUserAsync(userId);

            return(scopes);
        }
        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);
        }
        public async Task Test_Create_IdentityServerUser_Find_No_AllowedScopes_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);
            var scopes = await adminStore.FindScopesByUserAsync(userId);

            Assert.IsTrue(scopes.Count() == 0);
        }
        // GET: Admin/Home/Manage/5
        public async Task <ActionResult> Scopes(string id, string email)
        {
            // note this is POC.  We need a dynamic ajax page that does paging
            var usm = new UserScopeModel
            {
                AllowedScopes    = new List <UserScopeRecord>(),
                UserScopeRecords = new List <UserScopeRecord>(),
                Email            = email,
                UserId           = id
            };

            var fullUserStore = UserManager.FullUserStore;
            var adminStore    = new IdentityServer3AdminStore();
            var userScopes    = await adminStore.FindScopesByUserAsync(id);

            foreach (var scope in userScopes)
            {
                usm.UserScopeRecords.Add(new UserScopeRecord()
                {
                    Enabled = true, Name = scope
                });
            }
            int pageSize = 100;
            var page     = await adminStore.PageScopesAsync(100, null);

            var state  = HttpUtility.UrlEncode(page.PagingState);
            var record = new IDSScopePageRecord()
            {
                CurrentPagingState = HttpUtility.UrlEncode(page.CurrentPagingState),
                PageSize           = pageSize,
                PagingState        = HttpUtility.UrlEncode(page.PagingState),
                Scopes             = page
            };

            foreach (var scope in page)
            {
                usm.AllowedScopes.Add(new UserScopeRecord()
                {
                    Enabled = false,
                    Name    = scope.Name
                });
            }
            return(View(usm));
        }