Example #1
0
        public async Task <Resources> GetAllResourcesAsync()
        {
            var identity = await _identityResourceRepository.GetAllIdentityResourceList();

            IEnumerable <IdentityServer4.Models.IdentityResource> identityResources = new List <IdentityServer4.Models.IdentityResource>();

            if (identity != null && identity.Any())
            {
                identityResources = identity.Select(x => new IdentityServer4.Models.IdentityResource
                {
                    Enabled                 = x.Enabled,
                    Name                    = x.Name,
                    DisplayName             = x.DisplayName,
                    Description             = x.Description,
                    Required                = x.Required,
                    Emphasize               = x.Emphasize,
                    ShowInDiscoveryDocument = x.ShowInDiscoveryDocument,
                    UserClaims              = x.UserClaims.Select(y => y.Type).ToList(),
                    Properties              = x.Properties.ToDictionary(k => k.Key, v => v.Value)
                }).ToArray();
            }

            var apis = await _apiResourceRepository.GetApiResourcesByNameAsync(null);

            IEnumerable <IdentityServer4.Models.ApiResource> apiResources = new List <IdentityServer4.Models.ApiResource>();

            if (apis != null && apis.Any())
            {
                apiResources = apis.Select(x => new IdentityServer4.Models.ApiResource
                {
                    Enabled     = x.Enabled,
                    Name        = x.Name,
                    DisplayName = x.DisplayName,
                    Description = x.Description,
                    AllowedAccessTokenSigningAlgorithms = Convert(x.AllowedAccessTokenSigningAlgorithms),
                    ShowInDiscoveryDocument             = x.ShowInDiscoveryDocument,
                    ApiSecrets = x.Secrets.Select(s => new Secret
                    {
                        Description = s.Description,
                        Value       = s.Value,
                        Expiration  = s.Expiration,
                        Type        = s.Type
                    }).ToArray(),
                    Scopes     = x.Scopes.Select(s => s.Scope).ToArray(),
                    UserClaims = x.UserClaims.Select(c => c.Type).ToArray(),
                    Properties = x.Properties.ToDictionary(k => k.Key, v => v.Value)
                });
            }

            var scopes = await _apiScopeRepository.GetAllApiScopeListAsync();

            IEnumerable <IdentityServer4.Models.ApiScope> apiScopes = new List <IdentityServer4.Models.ApiScope>();

            if (scopes != null && scopes.Any())
            {
                apiScopes = scopes.Select(x => new IdentityServer4.Models.ApiScope
                {
                    Enabled                 = x.Enabled,
                    Name                    = x.Name,
                    DisplayName             = x.DisplayName,
                    Description             = x.Description,
                    Required                = x.Required,
                    Emphasize               = x.Emphasize,
                    ShowInDiscoveryDocument = x.ShowInDiscoveryDocument,
                    UserClaims              = x.UserClaims.Select(c => c.Type).ToList(),
                    Properties              = x.Properties.ToDictionary(k => k.Key, v => v.Value)
                }).ToArray();
            }

            var result = new Resources(identityResources, apiResources, apiScopes);

            return(result);
        }