From 9cb88782f50b671e915edc1b5d4b576064b10b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Thu, 1 Sep 2022 17:49:12 +0200 Subject: [PATCH] Make the issuer optional for sign-out operations when only one registration was added --- src/OpenIddict.Abstractions/OpenIddictResources.resx | 3 +++ src/OpenIddict.Client/OpenIddictClientHandlers.cs | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/OpenIddict.Abstractions/OpenIddictResources.resx b/src/OpenIddict.Abstractions/OpenIddictResources.resx index 224c56cf..0dac8974 100644 --- a/src/OpenIddict.Abstractions/OpenIddictResources.resx +++ b/src/OpenIddict.Abstractions/OpenIddictResources.resx @@ -1319,6 +1319,9 @@ Alternatively, you can disable the token storage feature by calling 'services.Ad The endpoint type associated with the state token cannot be resolved. + + No issuer was specified in the sign-out properties. When multiple clients are registered, an issuer must be specified in the sign-out properties. + The security token is missing. diff --git a/src/OpenIddict.Client/OpenIddictClientHandlers.cs b/src/OpenIddict.Client/OpenIddictClientHandlers.cs index 0684cfb7..e5adb13a 100644 --- a/src/OpenIddict.Client/OpenIddictClientHandlers.cs +++ b/src/OpenIddict.Client/OpenIddictClientHandlers.cs @@ -4468,6 +4468,16 @@ public static partial class OpenIddictClientHandlers throw new InvalidOperationException(SR.GetResourceString(SR.ID0024)); } + // If no issuer was explicitly attached and a single client is registered, use it. + // Otherwise, throw an exception to indicate that setting an explicit issuer + // is required when multiple clients are registered. + context.Issuer ??= context.Options.Registrations.Count switch + { + 0 => throw new InvalidOperationException(SR.GetResourceString(SR.ID0304)), + 1 => context.Options.Registrations[0].Issuer, + _ => throw new InvalidOperationException(SR.GetResourceString(SR.ID0341)) + }; + return default; } }