Ejemplo n.º 1
0
        private void ClientConnected(object _, SocketAcceptedEventArgs eventArgs)
        {
            try
            {
                var clientSession = ServiceProvider.GetRequiredService <IClient>();

                clientSession.Setup(eventArgs.Socket);

                clientSession.OnDisconnected += ClientDisconnected;
                clientSession.OnDataReceived += ClientDataReceived;

                // must add the socket to client store before calling StartReceiveProcess
                // otherwise we might receive messages before having access to client in client store
                _clientStore.Add(clientSession);

                clientSession.StartReceiveProcess();
                clientSession.StartSendProcess();

                _logger.LogInformation($"Client: {clientSession.Id} connected");
            }
            catch (ObjectDisposedException)
            {
                // ignore ObjectDisposedException
            }
        }
        public async Task <Client> AddClient(Client client)
        {
            client.TopLevelSecurableItem = new SecurableItem
            {
                Id   = Guid.NewGuid(),
                Name = client.Id
            };

            return(await _clientStore.Add(client));
        }
Ejemplo n.º 3
0
        public async Task <Client> AddClient(Client client)
        {
            client.TopLevelSecurableItem = new SecurableItem
            {
                Id          = Guid.NewGuid(),
                Name        = client.Id,
                ClientOwner = client.Id,
                Grain       = Defaults.Authorization.AppGrain
            };

            return(await _clientStore.Add(client));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public async Task <ClientSummary> Add(NewClient model)
        {
            int rand = new Random().Next();

            var entity = new Data.Client();

            entity.Name        = model.Name ?? $"new-client-{_profile.Name.ToKebabCase()}-{rand.ToString("x")}";
            entity.DisplayName = model.DisplayName ?? entity.Name;
            entity.Grants      = "client_credentials";

            entity.Enabled = _profile.IsPrivileged;

            if (!_profile.IsPrivileged)
            {
                entity.Managers.Add(new Data.ClientManager {
                    SubjectId = _profile.Id, Name = _profile.Name
                });
            }

            await _store.Add(entity);

            return(Mapper.Map <ClientSummary>(entity));
        }