Exemplo n.º 1
0
        public async Task <int> ExecuteAsync(CancellationToken cancellationToken)
        {
            var clientName = _clientName.Value() ?? string.Empty;

            if (string.IsNullOrWhiteSpace(clientName))
            {
                ShowHelp(true);
                return(1);
            }

            var client = await _clientsService.GetClientAsync(clientName);

            if (client is null)
            {
                _logger.LogInformation("Client not found.");
                return(1);
            }

            try
            {
                var token = await _authService.GetTokenAsync(client);

                _logger.LogInformation("Token: {@token}", token);

                if (_commonSettings.CopyAccessTokenToClipboard)
                {
                    await ClipboardService.SetTextAsync($"Bearer {token.AccessToken}", cancellationToken);

                    _logger.LogInformation("Token has been copied to clipboard.");
                }

                return(0);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(ex.HResult);
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Client> > GetClient(string id)
        {
            var client = await _clientsService.GetClientAsync(id);

            return(Ok(client));
        }