From 9c1bdfb288058f41461126e015a3c1845c8a71fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Tue, 21 Jun 2022 19:02:09 +0200 Subject: [PATCH] Update the client and validation stacks to log requests and responses --- .../OpenIddictResources.resx | 30 +++++++++++++++++++ .../OpenIddictClientService.cs | 17 +++++++++++ .../OpenIddictValidationService.cs | 13 ++++++++ 3 files changed, 60 insertions(+) diff --git a/src/OpenIddict.Abstractions/OpenIddictResources.resx b/src/OpenIddict.Abstractions/OpenIddictResources.resx index f92f07c4..9794dd4d 100644 --- a/src/OpenIddict.Abstractions/OpenIddictResources.resx +++ b/src/OpenIddict.Abstractions/OpenIddictResources.resx @@ -2293,6 +2293,36 @@ This may indicate that the hashed entry is corrupted or malformed. An unsupported {StatusCode} response was returned by the remote HTTP server: {ContentType} {Payload}. + + The configuration request was successfully sent to {Address}: {Request}. + + + The configuration response returned by {Address} was successfully extracted: {Response}. + + + The cryptography request was successfully sent to {Address}: {Request}. + + + The cryptography response returned by {Address} was successfully extracted: {Response}. + + + The introspection request was successfully sent to {Address}: {Request}. + + + The introspection response returned by {Address} was successfully extracted: {Response}. + + + The token request was successfully sent to {Address}: {Request}. + + + The token response returned by {Address} was successfully extracted: {Response}. + + + The userinfo request was successfully sent to {Address}: {Request}. + + + The userinfo response returned by {Address} was successfully extracted: {Response}. + https://documentation.openiddict.com/errors/{0} diff --git a/src/OpenIddict.Client/OpenIddictClientService.cs b/src/OpenIddict.Client/OpenIddictClientService.cs index 04e046ea..57180da9 100644 --- a/src/OpenIddict.Client/OpenIddictClientService.cs +++ b/src/OpenIddict.Client/OpenIddictClientService.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.Security.Claims; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; namespace OpenIddict.Client; @@ -111,6 +112,8 @@ public class OpenIddictClientService context.Error, context.ErrorDescription, context.ErrorUri); } + context.Logger.LogInformation(SR.GetResourceString(SR.ID6186), context.Address, context.Request); + return context.Request; } @@ -135,6 +138,8 @@ public class OpenIddictClientService Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007)); + context.Logger.LogInformation(SR.GetResourceString(SR.ID6187), context.Address, context.Response); + return context.Response; } @@ -266,6 +271,8 @@ public class OpenIddictClientService context.Error, context.ErrorDescription, context.ErrorUri); } + context.Logger.LogInformation(SR.GetResourceString(SR.ID6188), context.Address, context.Request); + return context.Request; } @@ -290,6 +297,8 @@ public class OpenIddictClientService Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007)); + context.Logger.LogInformation(SR.GetResourceString(SR.ID6189), context.Address, context.Response); + return context.Response; } @@ -686,6 +695,8 @@ public class OpenIddictClientService context.Error, context.ErrorDescription, context.ErrorUri); } + context.Logger.LogInformation(SR.GetResourceString(SR.ID6192), context.Address, context.Request); + return context.Request; } @@ -711,6 +722,8 @@ public class OpenIddictClientService Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007)); + context.Logger.LogInformation(SR.GetResourceString(SR.ID6193), context.Address, context.Response); + return context.Response; } @@ -853,6 +866,8 @@ public class OpenIddictClientService context.Error, context.ErrorDescription, context.ErrorUri); } + context.Logger.LogInformation(SR.GetResourceString(SR.ID6194), context.Address, context.Request); + return context.Request; } @@ -878,6 +893,8 @@ public class OpenIddictClientService Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007)); + context.Logger.LogInformation(SR.GetResourceString(SR.ID6195), context.Address, context.Response); + return (context.Response, context.UserinfoToken); } diff --git a/src/OpenIddict.Validation/OpenIddictValidationService.cs b/src/OpenIddict.Validation/OpenIddictValidationService.cs index dd8f473d..498f37a1 100644 --- a/src/OpenIddict.Validation/OpenIddictValidationService.cs +++ b/src/OpenIddict.Validation/OpenIddictValidationService.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.Security.Claims; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Tokens; namespace OpenIddict.Validation; @@ -100,6 +101,8 @@ public class OpenIddictValidationService context.Error, context.ErrorDescription, context.ErrorUri); } + context.Logger.LogInformation(SR.GetResourceString(SR.ID6186), context.Address, context.Request); + return context.Request; } @@ -122,6 +125,8 @@ public class OpenIddictValidationService Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007)); + context.Logger.LogInformation(SR.GetResourceString(SR.ID6187), context.Address, context.Response); + return context.Response; } @@ -240,6 +245,8 @@ public class OpenIddictValidationService context.Error, context.ErrorDescription, context.ErrorUri); } + context.Logger.LogInformation(SR.GetResourceString(SR.ID6188), context.Address, context.Request); + return context.Request; } @@ -262,6 +269,8 @@ public class OpenIddictValidationService Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007)); + context.Logger.LogInformation(SR.GetResourceString(SR.ID6189), context.Address, context.Response); + return context.Response; } @@ -398,6 +407,8 @@ public class OpenIddictValidationService context.Error, context.ErrorDescription, context.ErrorUri); } + context.Logger.LogInformation(SR.GetResourceString(SR.ID6190), context.Address, context.Request); + return context.Request; } @@ -420,6 +431,8 @@ public class OpenIddictValidationService Debug.Assert(context.Response is not null, SR.GetResourceString(SR.ID4007)); + context.Logger.LogInformation(SR.GetResourceString(SR.ID6191), context.Address, context.Response); + return context.Response; }