diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs index 3fdd0aae1d..a8ac0e0357 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Auth/AuthService.cs @@ -45,5 +45,10 @@ namespace Volo.Abp.Cli.Auth FileHelper.DeleteIfExists(CliPaths.AccessToken); return Task.CompletedTask; } + + public static bool IsLoggedIn() + { + return File.Exists(CliPaths.AccessToken); + } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs index 81c64a3b5f..ca1a23fcfc 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs @@ -3,6 +3,7 @@ using System.IO; using System.Net.Http; using System.Text; using IdentityModel.Client; +using Volo.Abp.Cli.Auth; namespace Volo.Abp.Cli.Http { @@ -29,7 +30,7 @@ namespace Volo.Abp.Cli.Http private static void AddAuthentication(HttpClient client) { - if (!File.Exists(CliPaths.AccessToken)) + if (!AuthService.IsLoggedIn()) { return; } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs index e1939f37cc..a22b6bba4a 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Polly; using Polly.Extensions.Http; +using Volo.Abp.Cli.Auth; using Volo.Abp.Cli.Http; using Volo.Abp.Cli.ProjectBuilding; using Volo.Abp.DependencyInjection; @@ -31,6 +32,11 @@ namespace Volo.Abp.Cli.Licensing public async Task GetApiKeyOrNullAsync(bool invalidateCache = false) { + if (!AuthService.IsLoggedIn()) + { + return null; + } + if (invalidateCache) { _apiKeyResult = null; @@ -81,16 +87,6 @@ namespace Volo.Abp.Cli.Licensing var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var apiKeyResult = JsonSerializer.Deserialize(responseContent); - if (string.IsNullOrEmpty(apiKeyResult?.ApiKey)) - { - _logger.LogError("Couldn't retrieve your NuGet API key!"); - _logger.LogWarning(File.Exists(CliPaths.AccessToken) - ? "Make sure you have an active session and license on commercial.abp.io. To re-sign in you can use the CLI command \"abp login \"." - : "You are not signed in to commercial.abp.io. Use the CLI command \"abp login \" to sign in."); - - return null; - } - return apiKeyResult; } }