Example #1
0
        public async Task <IActionResult> CreatePc()
        {
            var ab = _configurationDbContext.IdentityResources;

            //获取所有启用的resource
            var resources = await _resourceStore.GetAllEnabledResourcesAsync();

            var vm = new ManageViewModel();

            if (resources != null && (resources.IdentityResources.Any() || resources.ApiResources.Any()))
            {
                if (resources.IdentityResources.Any())
                {
                    vm.IdentityScopes = resources.IdentityResources.Select(x => ConfiguratioBase.CreateScopeViewModel(x)).ToArray();
                }
                if (resources.ApiResources.Any())
                {
                    vm.ResourceScopes = resources.ApiResources.SelectMany(x => x.Scopes).Select(x => ConfiguratioBase.CreateScopeViewModel(x)).ToArray();
                }
            }
            return(View(vm));
        }
Example #2
0
        public async Task <IActionResult> Index()
        {
            //http://www.cocoachina.com/articles/112766
            //var cks12 = HttpContext.RequestServices.GetRequiredService<ConfigurationDbContext>();

            var vmList = new List <ApplicationViewModel>();
            ApplicationViewModel vm = null;
            var userId = int.Parse(User.FindFirstValue("sub"));

            //var client = _configurationDbContext.Clients;
            var app = _applicationDbContext.userClients.Where(_ => _.UserId == userId);

            if (app != null && app.Any())
            {
                foreach (var item in app)
                {
                    var client = await ConfiguratioBase.GetClientAsync(_configurationDbContext, item.ClientId);

                    if (client != null)
                    {
                        vm = new ApplicationViewModel
                        {
                            ClientId = client.ClientId,
                            //ClientSecrets = client.ClientSecrets.Find(_ => _.ClientId == client.Id).Value,
                            ClientSecrets = client.Claims.Find(c => c.Type == "secret").Value,
                            Created       = client.Created,
                            Enable        = client.Enabled,
                            AllowedScopes = client.AllowedScopes,
                            ClientName    = client.ClientName,
                            Type          = item.Type,
                            Id            = client.Id,
                            GrantType     = client.AllowedGrantTypes.Find(_ => _.ClientId == item.ClientId)?.GrantType,
                        };
                        var resources = await _resourceStore.GetAllEnabledResourcesAsync();

                        if (resources != null && (resources.IdentityResources.Any() || resources.ApiResources.Any()))
                        {
                            vm.scopeViewModels = new List <ScopeViewModel>();
                            if (resources.IdentityResources.Any())
                            {
                                var resource = resources.IdentityResources.Select(x => ConfiguratioBase.CreateScopeViewModel(x)).ToArray();
                                if (resource != null && resource.Any())
                                {
                                    vm.scopeViewModels.AddRange(resource);
                                }
                            }
                            if (resources.ApiResources.Any())
                            {
                                var resource = resources.ApiResources.SelectMany(x => x.Scopes).Select(x => ConfiguratioBase.CreateScopeViewModel(x)).ToArray();
                                if (resource != null && resource.Any())
                                {
                                    vm.scopeViewModels.AddRange(resource);
                                }
                            }
                        }
                        vmList.Add(vm);
                    }
                }
            }
            return(View(vmList));
        }