diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs index d367c7b09e..22813d3d2d 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Net.Http; using System.Reflection; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; using Volo.Abp.DynamicProxy; @@ -29,6 +31,8 @@ namespace Volo.Abp.Http.Client.DynamicProxying private readonly IJsonSerializer _jsonSerializer; private readonly IRemoteServiceHttpClientAuthenticator _clientAuthenticator; + public ILogger> Logger { get; set; } + static DynamicHttpProxyInterceptor() { GenericInterceptAsyncMethod = typeof(DynamicHttpProxyInterceptor) @@ -50,6 +54,8 @@ namespace Volo.Abp.Http.Client.DynamicProxying _clientAuthenticator = clientAuthenticator; _clientOptions = clientOptions.Value; _remoteServiceOptions = remoteServiceOptions.Value; + + Logger = NullLogger>.Instance; } public override void Intercept(IAbpMethodInvocation invocation) diff --git a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs index 4a0daea58d..85bf78a9c2 100644 --- a/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs +++ b/framework/src/Volo.Abp.IdentityModel/Volo/Abp/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs @@ -4,6 +4,8 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using IdentityModel; using IdentityModel.Client; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; @@ -12,12 +14,15 @@ namespace Volo.Abp.IdentityModel [Dependency(ReplaceServices = true)] public class IdentityModelHttpClientAuthenticator : IIdentityModelHttpClientAuthenticator, ITransientDependency { - protected IdentityClientOptions ClientOptions { get; } + public ILogger Logger { get; set; } + protected IdentityClientOptions ClientOptions { get; } + public IdentityModelHttpClientAuthenticator( IOptions options) { ClientOptions = options.Value; + Logger = NullLogger.Instance; } public async Task Authenticate(IdentityModelHttpClientAuthenticateContext context) @@ -34,22 +39,27 @@ namespace Volo.Abp.IdentityModel protected virtual async Task GetAccessTokenFromServerOrNullAsync(IdentityModelHttpClientAuthenticateContext context) { + //TODO: Better logging + var configuration = GetClientConfiguration(context); if (configuration == null) { + Logger.LogWarning($"Could not find {nameof(IdentityClientConfiguration)} for {context.IdentityClientName}. Either define a configuration for {context.IdentityClientName} or set a default configuration."); return null; } var discoveryResponse = await GetDiscoveryResponse(configuration); if (discoveryResponse.IsError) { + Logger.LogError($"Could not retrieve the OpenId Connect discovery document! ErrorType: {discoveryResponse.ErrorType}. Error: {discoveryResponse.Error}"); return null; } var tokenResponse = await GetTokenResponse(discoveryResponse, configuration); if (tokenResponse.IsError) { + Logger.LogError($"Could not get token from the OpenId Connect server! ErrorType: {tokenResponse.ErrorType}. Error: {tokenResponse.Error}. ErrorDescription: {tokenResponse.ErrorDescription}. HttpStatusCode: {tokenResponse.HttpStatusCode}"); return null; }