public async Task <ClientSummary[]> Find(SearchModel search) { var query = _store.List(search.Term); if (search.Filter.Contains("published")) { query = query.Where(c => c.Flags.HasFlag(ClientFlag.Published)); } else if (!_profile.IsPrivileged) { query = query.Where(c => c.Managers.Any(m => m.SubjectId == _profile.Id)); } query = query.OrderBy(c => c.DisplayName); if (search.Skip > 0) { query = query.Skip(search.Skip); } if (search.Take > 0) { query = query.Take(search.Take); } var clients = await query.ToArrayAsync(); return(Mapper.Map <ClientSummary[]>(clients)); }
private async Task ImportClient(ClientImport client, Data.Resource[] resources) { string guid = Guid.NewGuid().ToString(); var clients = await _clients.List().ToArrayAsync(); var entity = clients.Where(c => c.Name == client.Id).SingleOrDefault(); if (entity != null) { guid = entity.GlobalId; await _clients.Delete(entity.Id); } entity = new Data.Client { Name = client.Id, GlobalId = guid, Enabled = true, DisplayName = client.DisplayName ?? client.Id, Grants = client.GrantType, Scopes = client.Scopes, Flags = ClientFlag.Published | ClientFlag.EnableLocalLogin | ClientFlag.AllowOfflineAccess | ClientFlag.AllowRememberConsent }; if ("implicit hybrid".Contains(client.GrantType)) { entity.Flags |= ClientFlag.AllowAccessTokensViaBrowser; } if (client.RedirectUrl.HasValue()) { entity.Urls = new Data.ClientUri[] { new Data.ClientUri { Type = ClientUriType.RedirectUri, Value = client.RedirectUrl } }; } if (client.Secret.HasValue()) { entity.Secrets.Add( new Data.ClientSecret { Type = "SharedSecret", Value = client.Secret.Sha256(), Description = "Added by Admin at " + DateTime.UtcNow.ToString("u") } ); } await _clients.Add(entity); }