From 93dd3ba0f41402f7923a9d16aa403e98ca288862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Wed, 25 Aug 2021 20:26:11 +0200 Subject: [PATCH] Cache the ProcessAuthenticationContext instance to avoid having to re-authenticate userinfo/revocation/introspection requests --- .../OpenIddictServerHandlers.Introspection.cs | 4 ++++ src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs | 4 ++++ src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs index ffb4042d..0eb3694b 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Introspection.cs @@ -700,6 +700,10 @@ namespace OpenIddict.Server var notification = new ProcessAuthenticationContext(context.Transaction); await _dispatcher.DispatchAsync(notification); + // Store the context object in the transaction so it can be later retrieved by handlers + // that want to access the authentication result without triggering a new authentication flow. + context.Transaction.SetProperty(typeof(ProcessAuthenticationContext).FullName!, notification); + if (notification.IsRequestHandled) { context.HandleRequest(); diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs index 366b0ddb..6b5ef32e 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Revocation.cs @@ -643,6 +643,10 @@ namespace OpenIddict.Server var notification = new ProcessAuthenticationContext(context.Transaction); await _dispatcher.DispatchAsync(notification); + // Store the context object in the transaction so it can be later retrieved by handlers + // that want to access the authentication result without triggering a new authentication flow. + context.Transaction.SetProperty(typeof(ProcessAuthenticationContext).FullName!, notification); + if (notification.IsRequestHandled) { context.HandleRequest(); diff --git a/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs b/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs index e97b547f..793e0aa0 100644 --- a/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs +++ b/src/OpenIddict.Server/OpenIddictServerHandlers.Userinfo.cs @@ -380,6 +380,10 @@ namespace OpenIddict.Server var notification = new ProcessAuthenticationContext(context.Transaction); await _dispatcher.DispatchAsync(notification); + // Store the context object in the transaction so it can be later retrieved by handlers + // that want to access the authentication result without triggering a new authentication flow. + context.Transaction.SetProperty(typeof(ProcessAuthenticationContext).FullName!, notification); + if (notification.IsRequestHandled) { context.HandleRequest();