Ejemplo n.º 1
0
        public void GetResourceByScopeNamePassingTest()
        {
            var resources = IdentityServerDBHelper.GetResourceByScopeName(ConnectionConst.CORRECTCONNECTIONSTRING,
                                                                          "ManageUser").Result;

            Assert.NotNull(resources);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <ApiResource> > FindApiResourcesByScopeAsync(IEnumerable <string> scopeNames)
        {
            List <ApiResource> resources = new List <ApiResource>();

            try
            {
                foreach (string sn in scopeNames)
                {
                    var resourcesFromDB = await IdentityServerDBHelper.GetResourceByScopeName(
                        Startup.Configuration.GetSection("ConnectionString").Value, sn);

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