Exemple #1
0
        public void GetAllResourcesPassingTest()
        {
            var resources = IdentityServerDBHelper.GetAllResources(ConnectionConst.CORRECTCONNECTIONSTRING).Result;

            Assert.NotNull(resources);
        }
Exemple #2
0
        public async Task <Resources> GetAllResources()
        {
            List <ApiResource> apiResources = new List <ApiResource>();

            try
            {
                var resourcesFromDB = await IdentityServerDBHelper.GetAllResources(
                    Startup.Configuration.GetSection("ConnectionString").Value);

                if (resourcesFromDB != null && resourcesFromDB.Count != 0)
                {
                    for (int i = 0; i < resourcesFromDB.Count; i++)
                    {
                        if (apiResources.Where(
                                r => r.Name == resourcesFromDB[i].resourceName).ToList().Count > 0)
                        {
                            apiResources.Where(
                                r => r.Name == resourcesFromDB[i].resourceName).ToList()[0].Scopes.Add(
                                new Scope()
                            {
                                Name        = resourcesFromDB[i].scopeName,
                                DisplayName = resourcesFromDB[i].scopeDisplayName,
                                Description = resourcesFromDB[i].scopeDescription
                            });
                        }
                        else
                        {
                            ApiResource apiResource = new ApiResource();
                            apiResource.Name        = resourcesFromDB[i].resourceName;
                            apiResource.Description = resourcesFromDB[i].resourceDescription;
                            string apiSecrets = resourcesFromDB[i].resourceSecrets;
                            apiResource.ApiSecrets = new List <Secret>()
                            {
                                new Secret(apiSecrets.Sha256()
                                           )
                            };
                            apiResource.Enabled = resourcesFromDB[i].enabled;
                            apiResource.Scopes  = new List <Scope>()
                            {
                                new Scope()
                                {
                                    Name        = resourcesFromDB[i].scopeName,
                                    DisplayName = resourcesFromDB[i].scopeDisplayName,
                                    Description = resourcesFromDB[i].scopeDescription
                                }
                            };
                            apiResource.UserClaims = new List <string>()
                            {
                                "role"
                            };
                            apiResources.Add(apiResource);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }
            return(new Resources()
            {
                ApiResources = apiResources
            });
        }