From 41f21440266acbc3badcf3d4b332808ed02ed7aa Mon Sep 17 00:00:00 2001 From: support Date: Thu, 22 Oct 2026 22:26:04 +0200 Subject: [PATCH 1/8] Move the OpenID Connect sign-in infrastructure into Grand.Web.Common --- .../Configuration/OidcLoginConfig.cs | 3 + .../Authentication.OpenIdConnect.csproj | 18 +----- .../Components/OidcLoginViewComponent.cs | 1 + .../Controllers/OidcLoginController.cs | 2 +- .../EndpointProvider.cs | 2 +- .../Authentication.OpenIdConnect/Manifest.cs | 2 +- .../OidcLoginPlugin.cs | 1 + .../OpenIdConnect/OidcLoginControllerTests.cs | 2 +- .../OidcBackChannelLogoutEndpointTests.cs | 5 +- .../Oidc}/OidcLoginIdentityMapperTests.cs | 4 +- .../Security/Oidc}/OidcLoginProviderTests.cs | 11 ++-- .../Oidc}/OidcLoginSessionDataTests.cs | 4 +- .../Oidc}/OidcLogoutTokenValidatorTests.cs | 4 +- .../Oidc}/OidcProfileSynchronizerTests.cs | 4 +- .../Oidc}/OidcSignOutProviderTests.cs | 5 +- .../Security/Oidc}/OidcTokenRefresherTests.cs | 8 +-- .../Startup/OidcLoginStartupTests.cs | 62 +++++++++++++++++++ .../Grand.Web.Common/Grand.Web.Common.csproj | 1 + .../Oidc}/OidcBackChannelLogoutEndpoint.cs | 2 +- .../Oidc}/OidcLoginAuthenticationBuilder.cs | 2 +- .../Security/Oidc}/OidcLoginDefaults.cs | 8 +-- .../Security/Oidc}/OidcLoginIdentityMapper.cs | 2 +- .../Security/Oidc}/OidcLoginProvider.cs | 7 ++- .../Security/Oidc}/OidcLoginSessionData.cs | 2 +- .../Security/Oidc}/OidcLogoutToken.cs | 2 +- .../Oidc}/OidcLogoutTokenValidator.cs | 2 +- .../Security/Oidc}/OidcProfileSynchronizer.cs | 2 +- .../Security/Oidc}/OidcSignOutProvider.cs | 2 +- .../Security/Oidc}/OidcTokenRefresher.cs | 2 +- .../Startup/OidcLoginStartup.cs} | 28 ++++++--- src/Web/Grand.Web/App_Data/appsettings.json | 2 + 31 files changed, 133 insertions(+), 69 deletions(-) rename src/Tests/{Grand.Modules.Tests/Plugins/OpenIdConnect => Grand.Web.Common.Tests/Security/Oidc}/OidcBackChannelLogoutEndpointTests.cs (98%) rename src/Tests/{Grand.Modules.Tests/Plugins/OpenIdConnect => Grand.Web.Common.Tests/Security/Oidc}/OidcLoginIdentityMapperTests.cs (96%) rename src/Tests/{Grand.Modules.Tests/Plugins/OpenIdConnect => Grand.Web.Common.Tests/Security/Oidc}/OidcLoginProviderTests.cs (71%) rename src/Tests/{Grand.Modules.Tests/Plugins/OpenIdConnect => Grand.Web.Common.Tests/Security/Oidc}/OidcLoginSessionDataTests.cs (95%) rename src/Tests/{Grand.Modules.Tests/Plugins/OpenIdConnect => Grand.Web.Common.Tests/Security/Oidc}/OidcLogoutTokenValidatorTests.cs (98%) rename src/Tests/{Grand.Modules.Tests/Plugins/OpenIdConnect => Grand.Web.Common.Tests/Security/Oidc}/OidcProfileSynchronizerTests.cs (98%) rename src/Tests/{Grand.Modules.Tests/Plugins/OpenIdConnect => Grand.Web.Common.Tests/Security/Oidc}/OidcSignOutProviderTests.cs (96%) rename src/Tests/{Grand.Modules.Tests/Plugins/OpenIdConnect => Grand.Web.Common.Tests/Security/Oidc}/OidcTokenRefresherTests.cs (96%) create mode 100644 src/Tests/Grand.Web.Common.Tests/Startup/OidcLoginStartupTests.cs rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure => Web/Grand.Web.Common/Security/Oidc}/OidcBackChannelLogoutEndpoint.cs (99%) rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure => Web/Grand.Web.Common/Security/Oidc}/OidcLoginAuthenticationBuilder.cs (98%) rename src/{Plugins/Authentication.OpenIdConnect => Web/Grand.Web.Common/Security/Oidc}/OidcLoginDefaults.cs (69%) rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure => Web/Grand.Web.Common/Security/Oidc}/OidcLoginIdentityMapper.cs (97%) rename src/{Plugins/Authentication.OpenIdConnect => Web/Grand.Web.Common/Security/Oidc}/OidcLoginProvider.cs (79%) rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure => Web/Grand.Web.Common/Security/Oidc}/OidcLoginSessionData.cs (97%) rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure => Web/Grand.Web.Common/Security/Oidc}/OidcLogoutToken.cs (91%) rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure => Web/Grand.Web.Common/Security/Oidc}/OidcLogoutTokenValidator.cs (99%) rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure => Web/Grand.Web.Common/Security/Oidc}/OidcProfileSynchronizer.cs (98%) rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure => Web/Grand.Web.Common/Security/Oidc}/OidcSignOutProvider.cs (97%) rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure => Web/Grand.Web.Common/Security/Oidc}/OidcTokenRefresher.cs (98%) rename src/{Plugins/Authentication.OpenIdConnect/Infrastructure/StartupApplication.cs => Web/Grand.Web.Common/Startup/OidcLoginStartup.cs} (59%) diff --git a/src/Core/Grand.Infrastructure/Configuration/OidcLoginConfig.cs b/src/Core/Grand.Infrastructure/Configuration/OidcLoginConfig.cs index 0bd753d11..3191f96b1 100644 --- a/src/Core/Grand.Infrastructure/Configuration/OidcLoginConfig.cs +++ b/src/Core/Grand.Infrastructure/Configuration/OidcLoginConfig.cs @@ -21,6 +21,9 @@ public class OidcLoginConfig public string ClientSecret { get; set; } public string Scopes { get; set; } = "openid profile email offline_access"; + /// Order of the sign-in button among the external authentication methods + public int DisplayOrder { get; set; } + /// A back-office session ends after this much inactivity (sliding) public int StaffIdleTimeoutMinutes { get; set; } = DefaultStaffIdleTimeoutMinutes; diff --git a/src/Plugins/Authentication.OpenIdConnect/Authentication.OpenIdConnect.csproj b/src/Plugins/Authentication.OpenIdConnect/Authentication.OpenIdConnect.csproj index 653ee9744..8aded22b6 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Authentication.OpenIdConnect.csproj +++ b/src/Plugins/Authentication.OpenIdConnect/Authentication.OpenIdConnect.csproj @@ -15,20 +15,4 @@ $(OutputPath) - - - - - - - - - - - - \ No newline at end of file + diff --git a/src/Plugins/Authentication.OpenIdConnect/Components/OidcLoginViewComponent.cs b/src/Plugins/Authentication.OpenIdConnect/Components/OidcLoginViewComponent.cs index 4e002c047..a6c3d0d9b 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Components/OidcLoginViewComponent.cs +++ b/src/Plugins/Authentication.OpenIdConnect/Components/OidcLoginViewComponent.cs @@ -1,3 +1,4 @@ +using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Mvc; diff --git a/src/Plugins/Authentication.OpenIdConnect/Controllers/OidcLoginController.cs b/src/Plugins/Authentication.OpenIdConnect/Controllers/OidcLoginController.cs index f538c9610..1a55f272d 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Controllers/OidcLoginController.cs +++ b/src/Plugins/Authentication.OpenIdConnect/Controllers/OidcLoginController.cs @@ -1,4 +1,3 @@ -using Authentication.OpenIdConnect.Infrastructure; using Authentication.OpenIdConnect.Models; using Grand.Business.Core.Events.Customers; using Grand.Business.Core.Interfaces.Authentication; @@ -10,6 +9,7 @@ using Grand.Web.Common.Controllers; using Grand.Web.Common.Security.Authentication; using Grand.Web.Common.Security.ExternalRegistration; +using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; diff --git a/src/Plugins/Authentication.OpenIdConnect/EndpointProvider.cs b/src/Plugins/Authentication.OpenIdConnect/EndpointProvider.cs index 165cf45e2..f4292f2a0 100644 --- a/src/Plugins/Authentication.OpenIdConnect/EndpointProvider.cs +++ b/src/Plugins/Authentication.OpenIdConnect/EndpointProvider.cs @@ -1,6 +1,6 @@ -using Authentication.OpenIdConnect.Infrastructure; using Grand.Infrastructure.Endpoints; using Grand.Web.Common.Middleware; +using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; diff --git a/src/Plugins/Authentication.OpenIdConnect/Manifest.cs b/src/Plugins/Authentication.OpenIdConnect/Manifest.cs index 63e792322..5153a8b87 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Manifest.cs +++ b/src/Plugins/Authentication.OpenIdConnect/Manifest.cs @@ -1,4 +1,4 @@ -using Authentication.OpenIdConnect; +using Grand.Web.Common.Security.Oidc; using Grand.Infrastructure.Plugins; [assembly: PluginInfo( diff --git a/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs b/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs index b3d3947f3..5cbc5b92a 100644 --- a/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs +++ b/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs @@ -1,6 +1,7 @@ using Grand.Business.Core.Interfaces.Common.Configuration; using Grand.Business.Core.Interfaces.Common.Localization; using Grand.Infrastructure.Plugins; +using Grand.Web.Common.Security.Oidc; namespace Authentication.OpenIdConnect; diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginControllerTests.cs b/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginControllerTests.cs index a5964643f..211f09e79 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginControllerTests.cs +++ b/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginControllerTests.cs @@ -1,6 +1,5 @@ using Authentication.OpenIdConnect; using Authentication.OpenIdConnect.Controllers; -using Authentication.OpenIdConnect.Infrastructure; using Authentication.OpenIdConnect.Models; using Grand.Business.Core.Interfaces.Customers; using Grand.Infrastructure.Configuration; @@ -16,6 +15,7 @@ using Grand.Mediator; using Grand.Web.Common.Security.Authentication; using Grand.Web.Common.Security.ExternalRegistration; +using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcBackChannelLogoutEndpointTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs similarity index 98% rename from src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcBackChannelLogoutEndpointTests.cs rename to src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs index f68377397..683dff265 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcBackChannelLogoutEndpointTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs @@ -1,8 +1,7 @@ -using Authentication.OpenIdConnect; -using Authentication.OpenIdConnect.Infrastructure; using Grand.Business.Core.Interfaces.Authentication; using Grand.Domain.Customers; using Grand.Infrastructure.Configuration; +using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Http; @@ -19,7 +18,7 @@ using Moq; using System.Security.Cryptography; -namespace Grand.Modules.Tests.Plugins.OpenIdConnect; +namespace Grand.Web.Common.Tests.Security.Oidc; [TestClass] public class OidcBackChannelLogoutEndpointTests diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginIdentityMapperTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginIdentityMapperTests.cs similarity index 96% rename from src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginIdentityMapperTests.cs rename to src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginIdentityMapperTests.cs index e34fdf51c..2e8c6efb0 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginIdentityMapperTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginIdentityMapperTests.cs @@ -1,10 +1,10 @@ -using Authentication.OpenIdConnect.Infrastructure; using Grand.Infrastructure.Configuration; +using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Authentication; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Security.Claims; -namespace Grand.Modules.Tests.Plugins.OpenIdConnect; +namespace Grand.Web.Common.Tests.Security.Oidc; [TestClass] public class OidcLoginIdentityMapperTests diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginProviderTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginProviderTests.cs similarity index 71% rename from src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginProviderTests.cs rename to src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginProviderTests.cs index 1d1ac7166..165c947a9 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginProviderTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginProviderTests.cs @@ -1,11 +1,10 @@ -using Authentication.OpenIdConnect; using Grand.Infrastructure.Configuration; using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Authentication; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -namespace Grand.Modules.Tests.Plugins.OpenIdConnect; +namespace Grand.Web.Common.Tests.Security.Oidc; [TestClass] public class OidcLoginProviderTests @@ -16,24 +15,24 @@ public async Task PanelSignInPath_WithScheme() var schemes = new Mock(); schemes.Setup(x => x.GetSchemeAsync(OidcLoginDefaults.AuthenticationScheme)).ReturnsAsync( new AuthenticationScheme(OidcLoginDefaults.AuthenticationScheme, null, typeof(IAuthenticationHandler))); - var provider = new OidcLoginProvider(new OidcLoginSettings(), schemes.Object); + var provider = new OidcLoginProvider(new OidcLoginConfig(), schemes.Object); Assert.AreEqual("/oidc/login?returnUrl=%2Fadmin", await provider.GetSignInPath("/admin")); } [TestMethod] public async Task PanelSignInPath_NoScheme_Null() { - var provider = new OidcLoginProvider(new OidcLoginSettings(), new Mock().Object); + var provider = new OidcLoginProvider(new OidcLoginConfig(), new Mock().Object); Assert.IsNull(await provider.GetSignInPath("/admin")); } [TestMethod] public void SystemName_IsTheLinkName() => - Assert.AreEqual(OidcResourceServerDefaults.ProviderSystemName, new OidcLoginProvider(new OidcLoginSettings(), new Mock().Object).SystemName); + Assert.AreEqual(OidcResourceServerDefaults.ProviderSystemName, new OidcLoginProvider(new OidcLoginConfig(), new Mock().Object).SystemName); [TestMethod] public void Priority_FromSettings() => - Assert.AreEqual(7, new OidcLoginProvider(new OidcLoginSettings { DisplayOrder = 7 }, new Mock().Object).Priority); + Assert.AreEqual(7, new OidcLoginProvider(new OidcLoginConfig { DisplayOrder = 7 }, new Mock().Object).Priority); [TestMethod] [DataRow("https://idp", "client", true)] diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginSessionDataTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginSessionDataTests.cs similarity index 95% rename from src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginSessionDataTests.cs rename to src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginSessionDataTests.cs index fbf31fdeb..c8436a31f 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginSessionDataTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginSessionDataTests.cs @@ -1,4 +1,4 @@ -using Authentication.OpenIdConnect.Infrastructure; +using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Authentication; using Microsoft.IdentityModel.JsonWebTokens; using Microsoft.IdentityModel.Protocols.OpenIdConnect; @@ -7,7 +7,7 @@ using System.Security.Claims; using System.Text; -namespace Grand.Modules.Tests.Plugins.OpenIdConnect; +namespace Grand.Web.Common.Tests.Security.Oidc; [TestClass] public class OidcLoginSessionDataTests diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLogoutTokenValidatorTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLogoutTokenValidatorTests.cs similarity index 98% rename from src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLogoutTokenValidatorTests.cs rename to src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLogoutTokenValidatorTests.cs index 83b46655f..33d0218ef 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLogoutTokenValidatorTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLogoutTokenValidatorTests.cs @@ -1,4 +1,4 @@ -using Authentication.OpenIdConnect.Infrastructure; +using Grand.Web.Common.Security.Oidc; using Microsoft.Extensions.Caching.Memory; using Microsoft.IdentityModel.JsonWebTokens; using Microsoft.IdentityModel.Protocols.OpenIdConnect; @@ -7,7 +7,7 @@ using System.Security.Cryptography; using System.Text; -namespace Grand.Modules.Tests.Plugins.OpenIdConnect; +namespace Grand.Web.Common.Tests.Security.Oidc; [TestClass] public class OidcLogoutTokenValidatorTests diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcProfileSynchronizerTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcProfileSynchronizerTests.cs similarity index 98% rename from src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcProfileSynchronizerTests.cs rename to src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcProfileSynchronizerTests.cs index e504437c2..8a0e94733 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcProfileSynchronizerTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcProfileSynchronizerTests.cs @@ -1,15 +1,15 @@ -using Authentication.OpenIdConnect.Infrastructure; using Grand.Business.Core.Interfaces.Customers; using Grand.Domain.Common; using Grand.Domain.Customers; using Grand.Infrastructure.Configuration; using Grand.Web.Common.Security.ExternalRegistration; +using Grand.Web.Common.Security.Oidc; using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System.Linq.Expressions; -namespace Grand.Modules.Tests.Plugins.OpenIdConnect; +namespace Grand.Web.Common.Tests.Security.Oidc; [TestClass] public class OidcProfileSynchronizerTests diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcSignOutProviderTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcSignOutProviderTests.cs similarity index 96% rename from src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcSignOutProviderTests.cs rename to src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcSignOutProviderTests.cs index 17499096b..194fea428 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcSignOutProviderTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcSignOutProviderTests.cs @@ -1,8 +1,7 @@ -using Authentication.OpenIdConnect; -using Authentication.OpenIdConnect.Infrastructure; using Grand.Business.Core.Interfaces.Authentication; using Grand.Infrastructure; using Grand.Infrastructure.Configuration; +using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -11,7 +10,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -namespace Grand.Modules.Tests.Plugins.OpenIdConnect; +namespace Grand.Web.Common.Tests.Security.Oidc; [TestClass] public class OidcSignOutProviderTests diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcTokenRefresherTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcTokenRefresherTests.cs similarity index 96% rename from src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcTokenRefresherTests.cs rename to src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcTokenRefresherTests.cs index 1d3acc46d..a497e69a6 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcTokenRefresherTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcTokenRefresherTests.cs @@ -1,7 +1,7 @@ -using Authentication.OpenIdConnect; -using Authentication.OpenIdConnect.Infrastructure; using Grand.Business.Core.Utilities.Authentication; using Grand.Infrastructure.Configuration; +using Grand.Web.Common.Security.Oidc; +using Grand.Web.Common.Startup; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -14,7 +14,7 @@ using Moq; using System.Net; -namespace Grand.Modules.Tests.Plugins.OpenIdConnect; +namespace Grand.Web.Common.Tests.Security.Oidc; [TestClass] public class OidcTokenRefresherTests @@ -164,7 +164,7 @@ public async Task Redirect_Unavailable(HttpStatusCode status) public void HttpClient_DoesNotFollowRedirects() { var services = new ServiceCollection(); - new StartupApplication().ConfigureServices(services, new ConfigurationBuilder().Build()); + new OidcLoginStartup().ConfigureServices(services, new ConfigurationBuilder().Build()); using var provider = services.BuildServiceProvider(); var builder = provider.GetRequiredService(); diff --git a/src/Tests/Grand.Web.Common.Tests/Startup/OidcLoginStartupTests.cs b/src/Tests/Grand.Web.Common.Tests/Startup/OidcLoginStartupTests.cs new file mode 100644 index 000000000..a897d2c1f --- /dev/null +++ b/src/Tests/Grand.Web.Common.Tests/Startup/OidcLoginStartupTests.cs @@ -0,0 +1,62 @@ +using Grand.Business.Core.Interfaces.Authentication; +using Grand.Web.Common.Security.Oidc; +using Grand.Web.Common.Startup; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Grand.Web.Common.Tests.Startup; + +[TestClass] +public class OidcLoginStartupTests +{ + private static ServiceCollection ConfigureServices(string authority, string clientId) + { + var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary { + ["OidcResourceServer:Enabled"] = "true", + ["OidcResourceServer:Authority"] = authority, + ["OidcLogin:ClientId"] = clientId + }).Build(); + var services = new ServiceCollection(); + new OidcLoginStartup().ConfigureServices(services, configuration); + return services; + } + + private static ServiceDescriptor Find(IServiceCollection services, Type serviceType) => + services.SingleOrDefault(x => x.ServiceType == serviceType); + + [TestMethod] + public void ConfigureServices_Configured_RegistersOidcLoginServices() + { + var services = ConfigureServices("https://idp.test", "shop"); + + Assert.AreEqual(typeof(OidcLoginProvider), Find(services, typeof(IExternalAuthenticationProvider))?.ImplementationType); + Assert.AreEqual(typeof(OidcTokenRefresher), Find(services, typeof(IOidcTokenRefresher))?.ImplementationType); + Assert.AreEqual(typeof(OidcSignOutProvider), Find(services, typeof(IExternalSignOutProvider))?.ImplementationType); + Assert.AreEqual(ServiceLifetime.Scoped, Find(services, typeof(IExternalAuthenticationProvider)).Lifetime); + Assert.AreEqual(ServiceLifetime.Singleton, Find(services, typeof(OidcLogoutTokenValidator))?.Lifetime); + Assert.AreEqual(ServiceLifetime.Scoped, Find(services, typeof(OidcProfileSynchronizer))?.Lifetime); + } + + [TestMethod] + public void ConfigureServices_ClientIdEmpty_RegistersNoProvider() + { + AssertOnlyAlwaysRegisteredServices(ConfigureServices("https://idp.test", "")); + } + + [TestMethod] + public void ConfigureServices_ResourceServerAuthorityEmpty_RegistersNoProvider() + { + AssertOnlyAlwaysRegisteredServices(ConfigureServices("", "shop")); + } + + //the controller and the back-channel endpoint are always mapped and resolve these + private static void AssertOnlyAlwaysRegisteredServices(IServiceCollection services) + { + Assert.IsNull(Find(services, typeof(IExternalAuthenticationProvider))); + Assert.IsNull(Find(services, typeof(IOidcTokenRefresher))); + Assert.IsNull(Find(services, typeof(IExternalSignOutProvider))); + Assert.IsNotNull(Find(services, typeof(OidcLogoutTokenValidator))); + Assert.IsNotNull(Find(services, typeof(OidcProfileSynchronizer))); + } +} diff --git a/src/Web/Grand.Web.Common/Grand.Web.Common.csproj b/src/Web/Grand.Web.Common/Grand.Web.Common.csproj index f2542a14d..a71fb5633 100644 --- a/src/Web/Grand.Web.Common/Grand.Web.Common.csproj +++ b/src/Web/Grand.Web.Common/Grand.Web.Common.csproj @@ -12,6 +12,7 @@ + diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcBackChannelLogoutEndpoint.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs similarity index 99% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcBackChannelLogoutEndpoint.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs index fb09a2d52..7e18c6d60 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcBackChannelLogoutEndpoint.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Security.Oidc; /// /// OpenID Connect Back-Channel Logout 1.0: the identity provider tells the store that a provider session ended; the diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLoginAuthenticationBuilder.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginAuthenticationBuilder.cs similarity index 98% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLoginAuthenticationBuilder.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcLoginAuthenticationBuilder.cs index d0bbcf6eb..030f15133 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLoginAuthenticationBuilder.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginAuthenticationBuilder.cs @@ -9,7 +9,7 @@ using Microsoft.Extensions.Logging; using Microsoft.IdentityModel.Protocols.OpenIdConnect; -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Security.Oidc; /// /// Browser sign-in with the identity provider of the resource server (authorization code + PKCE) diff --git a/src/Plugins/Authentication.OpenIdConnect/OidcLoginDefaults.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginDefaults.cs similarity index 69% rename from src/Plugins/Authentication.OpenIdConnect/OidcLoginDefaults.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcLoginDefaults.cs index 84442bf64..b6199c3cb 100644 --- a/src/Plugins/Authentication.OpenIdConnect/OidcLoginDefaults.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginDefaults.cs @@ -1,10 +1,8 @@ -using Grand.Web.Common.Security.Oidc; - -namespace Authentication.OpenIdConnect; +namespace Grand.Web.Common.Security.Oidc; public static class OidcLoginDefaults { - /// Plugin system name; also the ExternalAuthentication link name shared with the resource server + /// System name of the OpenID Connect sign-in method; also the ExternalAuthentication link name shared with the resource server public const string ProviderSystemName = OidcResourceServerDefaults.ProviderSystemName; public const string AuthenticationScheme = "OidcLogin"; @@ -14,6 +12,6 @@ public static class OidcLoginDefaults public const string BackChannelLogoutPath = "oidc/backchannel-logout"; public const string LoginPath = "/oidc/login"; public const string FailedPath = "/oidc/failed"; - public const string ConfigurationUrl = "../OidcLoginSettings/Configure"; + public const string ConfigurationUrl = "../ExternalAuthentication/Methods"; public static readonly TimeSpan PendingLifetime = TimeSpan.FromMinutes(15); } diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLoginIdentityMapper.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginIdentityMapper.cs similarity index 97% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLoginIdentityMapper.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcLoginIdentityMapper.cs index f3eee17a4..c557eeab3 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLoginIdentityMapper.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginIdentityMapper.cs @@ -4,7 +4,7 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; using System.Security.Claims; -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Security.Oidc; public static class OidcLoginIdentityMapper { diff --git a/src/Plugins/Authentication.OpenIdConnect/OidcLoginProvider.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginProvider.cs similarity index 79% rename from src/Plugins/Authentication.OpenIdConnect/OidcLoginProvider.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcLoginProvider.cs index 7813fc754..2453f203a 100644 --- a/src/Plugins/Authentication.OpenIdConnect/OidcLoginProvider.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginProvider.cs @@ -1,9 +1,10 @@ using Grand.Business.Core.Interfaces.Authentication; +using Grand.Infrastructure.Configuration; using Microsoft.AspNetCore.Authentication; -namespace Authentication.OpenIdConnect; +namespace Grand.Web.Common.Security.Oidc; -public class OidcLoginProvider(OidcLoginSettings settings, IAuthenticationSchemeProvider authenticationSchemeProvider) +public class OidcLoginProvider(OidcLoginConfig config, IAuthenticationSchemeProvider authenticationSchemeProvider) : IExternalSignInPathProvider { public string ConfigurationUrl => OidcLoginDefaults.ConfigurationUrl; @@ -12,7 +13,7 @@ public class OidcLoginProvider(OidcLoginSettings settings, IAuthenticationScheme public string FriendlyName => "OpenID Connect"; - public int Priority => settings.DisplayOrder; + public int Priority => config.DisplayOrder; public IList LimitedToStores => new List(); diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLoginSessionData.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginSessionData.cs similarity index 97% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLoginSessionData.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcLoginSessionData.cs index aef9f092b..71a10c75a 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLoginSessionData.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginSessionData.cs @@ -4,7 +4,7 @@ using Microsoft.IdentityModel.JsonWebTokens; using Microsoft.IdentityModel.Protocols.OpenIdConnect; -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Security.Oidc; /// /// What the server-side session needs from the provider sign-in (refresh token, provider session id), carried from diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLogoutToken.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcLogoutToken.cs similarity index 91% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLogoutToken.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcLogoutToken.cs index f8a262cbb..1edab7b80 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLogoutToken.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcLogoutToken.cs @@ -1,4 +1,4 @@ -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Security.Oidc; /// The token is signed with a key the metadata does not list (yet): the provider may have rotated its keys public sealed record OidcLogoutToken(bool IsValid, string Subject, string Sid, string Error, string ReplayKey = null, diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLogoutTokenValidator.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcLogoutTokenValidator.cs similarity index 99% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLogoutTokenValidator.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcLogoutTokenValidator.cs index 69d409267..698b70d0d 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcLogoutTokenValidator.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcLogoutTokenValidator.cs @@ -4,7 +4,7 @@ using Microsoft.IdentityModel.Tokens; using System.Text.Json; -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Security.Oidc; /// /// Validates a logout token of OpenID Connect Back-Channel Logout 1.0 diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcProfileSynchronizer.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcProfileSynchronizer.cs similarity index 98% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcProfileSynchronizer.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcProfileSynchronizer.cs index 623aa9d29..105caa6d8 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcProfileSynchronizer.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcProfileSynchronizer.cs @@ -5,7 +5,7 @@ using Grand.Web.Common.Security.ExternalRegistration; using Microsoft.Extensions.Logging; -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Security.Oidc; /// /// ProviderOnly: the identity provider owns the name and the e-mail, so a provider sign-in copies them onto the diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcSignOutProvider.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcSignOutProvider.cs similarity index 97% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcSignOutProvider.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcSignOutProvider.cs index 78281a842..fb182a083 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcSignOutProvider.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcSignOutProvider.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Security.Oidc; /// /// Ends the session at the identity provider (OpenID Connect RP-Initiated Logout 1.0) through the end-session endpoint of its metadata. diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcTokenRefresher.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcTokenRefresher.cs similarity index 98% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcTokenRefresher.cs rename to src/Web/Grand.Web.Common/Security/Oidc/OidcTokenRefresher.cs index a7a039b5e..3cc7f48c8 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/OidcTokenRefresher.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcTokenRefresher.cs @@ -7,7 +7,7 @@ using System.Net; using System.Text.Json; -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Security.Oidc; /// /// Confirms a session signed in through the provider at the identity provider by exchanging its refresh token (RFC 6749, section 6) diff --git a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/StartupApplication.cs b/src/Web/Grand.Web.Common/Startup/OidcLoginStartup.cs similarity index 59% rename from src/Plugins/Authentication.OpenIdConnect/Infrastructure/StartupApplication.cs rename to src/Web/Grand.Web.Common/Startup/OidcLoginStartup.cs index 54b364e91..3eb0ae7ba 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Infrastructure/StartupApplication.cs +++ b/src/Web/Grand.Web.Common/Startup/OidcLoginStartup.cs @@ -1,31 +1,45 @@ using Grand.Business.Core.Interfaces.Authentication; using Grand.Infrastructure; +using Grand.Infrastructure.Configuration; +using Grand.Web.Common.Security.Oidc; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -namespace Authentication.OpenIdConnect.Infrastructure; +namespace Grand.Web.Common.Startup; -public class StartupApplication : IStartupApplication +/// +/// Browser sign-in with the identity provider of the resource server; the sign-in method exists only when +/// OidcResourceServer:Authority and OidcLogin:ClientId are set +/// +public class OidcLoginStartup : IStartupApplication { public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { - services.AddScoped(); //no redirects: a 307/308 from the token endpoint would re-post the refresh token and client secret elsewhere services.AddHttpClient(OidcLoginDefaults.HttpClientName, client => client.Timeout = TimeSpan.FromSeconds(10)) .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { AllowAutoRedirect = false }); - services.AddScoped(); - services.AddScoped(); + //the sign-in controller and the back-channel logout endpoint are always mapped services.AddSingleton(); services.AddScoped(); - } - public int Priority => 10; + var resourceServer = new OidcResourceServerConfig(); + configuration.GetSection("OidcResourceServer").Bind(resourceServer); + var login = new OidcLoginConfig(); + configuration.GetSection(OidcLoginDefaults.ConfigSection).Bind(login); + if (!login.IsConfigured(resourceServer)) + return; + + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + } public void Configure(WebApplication application, IWebHostEnvironment webHostEnvironment) { } + public int Priority => 502; public bool BeforeConfigure => false; } diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json index fc889babb..9650f07ba 100644 --- a/src/Web/Grand.Web/App_Data/appsettings.json +++ b/src/Web/Grand.Web/App_Data/appsettings.json @@ -303,6 +303,8 @@ //keep it out of source control (env var OidcLogin__ClientSecret or a secret store) "ClientSecret": "", "Scopes": "openid profile email offline_access", + //order of the sign-in button among the external authentication methods + "DisplayOrder": 0, //every session signed in through the provider confirms the account there this often (minutes); a user disabled at the provider loses access within this time "RevalidationMinutes": 10, //back-office accounts only (admin panel, store staff, vendors) signed in through the provider From d9eee9cc03ecc156cd2bfeabcc1a73850c316806 Mon Sep 17 00:00:00 2001 From: support Date: Thu, 22 Oct 2026 22:33:16 +0200 Subject: [PATCH 2/8] Show the OpenID Connect configuration on the external authentication page --- .../OidcLoginSettingsController.cs | 89 ------------------ .../Views/OidcLoginSettings/Configure.cshtml | 35 ------- .../Areas/Admin/_ViewImports.cshtml | 8 -- .../Models/ConfigurationModel.cs | 20 ---- .../OidcLoginPlugin.cs | 27 +----- .../OidcLoginSettings.cs | 8 -- .../ExternalAuthenticationControllerTests.cs | 57 +++++++++++ .../ExternalAuthentication/Methods.cshtml | 25 +++++ .../ExternalAuthenticationController.cs | 8 +- .../ExternalAuthentication/OidcLinksModel.cs | 6 ++ .../App_Data/Resources/DefaultLanguage.xml | Bin 1575718 -> 1578964 bytes .../App_Data/Resources/Upgrade/en_250.xml | 18 ++++ 12 files changed, 113 insertions(+), 188 deletions(-) delete mode 100644 src/Plugins/Authentication.OpenIdConnect/Areas/Admin/Controllers/OidcLoginSettingsController.cs delete mode 100644 src/Plugins/Authentication.OpenIdConnect/Areas/Admin/Views/OidcLoginSettings/Configure.cshtml delete mode 100644 src/Plugins/Authentication.OpenIdConnect/Areas/Admin/_ViewImports.cshtml delete mode 100644 src/Plugins/Authentication.OpenIdConnect/Models/ConfigurationModel.cs delete mode 100644 src/Plugins/Authentication.OpenIdConnect/OidcLoginSettings.cs create mode 100644 src/Tests/Grand.Web.Admin.Tests/Controllers/ExternalAuthenticationControllerTests.cs diff --git a/src/Plugins/Authentication.OpenIdConnect/Areas/Admin/Controllers/OidcLoginSettingsController.cs b/src/Plugins/Authentication.OpenIdConnect/Areas/Admin/Controllers/OidcLoginSettingsController.cs deleted file mode 100644 index 586640bf3..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/Areas/Admin/Controllers/OidcLoginSettingsController.cs +++ /dev/null @@ -1,89 +0,0 @@ -using Authentication.OpenIdConnect.Models; -using Grand.Business.Core.Interfaces.Common.Configuration; -using Grand.Domain.Permissions; -using Grand.Infrastructure.Configuration; -using Grand.Web.Common.Controllers; -using Grand.Web.Common.Security.Authorization; -using Microsoft.AspNetCore.Mvc; -using Grand.Web.Common.Localization; - -namespace Authentication.OpenIdConnect.Areas.Admin.Controllers; - -[PermissionAuthorize(PermissionSystemName.ExternalAuthenticationMethods)] -public class OidcLoginSettingsController : BaseAdminPluginController -{ - #region Ctor - - public OidcLoginSettingsController( - OidcLoginSettings oidcLoginSettings, - OidcResourceServerConfig resourceServerConfig, - OidcLoginConfig oidcLoginConfig, - IRequestTranslationService translationService, - IRequestPermissionService permissionService, - ISettingService settingService) - { - _oidcLoginSettings = oidcLoginSettings; - _resourceServerConfig = resourceServerConfig; - _oidcLoginConfig = oidcLoginConfig; - _translationService = translationService; - _permissionService = permissionService; - _settingService = settingService; - } - - #endregion - - #region Fields - - private readonly OidcLoginSettings _oidcLoginSettings; - private readonly OidcResourceServerConfig _resourceServerConfig; - private readonly OidcLoginConfig _oidcLoginConfig; - private readonly IRequestTranslationService _translationService; - private readonly IRequestPermissionService _permissionService; - private readonly ISettingService _settingService; - - #endregion - - #region Methods - - public async Task Configure() - { - if (!await _permissionService.Authorize(StandardPermission.ManageExternalAuthenticationMethods)) - return AccessDeniedView(); - - var model = new ConfigurationModel { - Authority = _resourceServerConfig.Authority, - ClientId = _oidcLoginConfig.ClientId, - //never the secret itself - ClientSecret = _translationService.GetResource(string.IsNullOrWhiteSpace(_oidcLoginConfig.ClientSecret) - ? "Plugins.ExternalAuth.OpenIdConnect.ClientSecret.NotSet" - : "Plugins.ExternalAuth.OpenIdConnect.ClientSecret.Set"), - DisplayOrder = _oidcLoginSettings.DisplayOrder - }; - - return View(model); - } - - [HttpPost] - [AutoValidateAntiforgeryToken] - public async Task Configure(ConfigurationModel model) - { - if (!await _permissionService.Authorize(StandardPermission.ManageExternalAuthenticationMethods)) - return AccessDeniedView(); - - if (!ModelState.IsValid) - return await Configure(); - - _oidcLoginSettings.DisplayOrder = model.DisplayOrder; - - await _settingService.SaveSetting(_oidcLoginSettings); - - //now clear settings cache - await _settingService.ClearCache(); - - Success(_translationService.GetResource("Admin.Plugins.Saved")); - - return await Configure(); - } - - #endregion -} diff --git a/src/Plugins/Authentication.OpenIdConnect/Areas/Admin/Views/OidcLoginSettings/Configure.cshtml b/src/Plugins/Authentication.OpenIdConnect/Areas/Admin/Views/OidcLoginSettings/Configure.cshtml deleted file mode 100644 index 1a5ba11e1..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/Areas/Admin/Views/OidcLoginSettings/Configure.cshtml +++ /dev/null @@ -1,35 +0,0 @@ -@model Authentication.OpenIdConnect.Models.ConfigurationModel -@{ - Layout = "_AdminLayout"; - ViewBag.Title = "OpenID Connect"; -} - - -@* the identity provider and the client come from appsettings and are shown read-only; the secret is never shown *@ -
- - - - - -
- @Html.Raw(Loc["Plugins.ExternalAuth.OpenIdConnect.Description"]) -
- -
- - - - - - - - - - -
-
-
-
diff --git a/src/Plugins/Authentication.OpenIdConnect/Areas/Admin/_ViewImports.cshtml b/src/Plugins/Authentication.OpenIdConnect/Areas/Admin/_ViewImports.cshtml deleted file mode 100644 index 4a79413f8..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/Areas/Admin/_ViewImports.cshtml +++ /dev/null @@ -1,8 +0,0 @@ -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers -@addTagHelper *, Grand.Web.Common - -@using Microsoft.AspNetCore.Mvc.ViewFeatures -@using Grand.Infrastructure.Extensions -@using Grand.Web.Common.Localization - -@inject LocService Loc \ No newline at end of file diff --git a/src/Plugins/Authentication.OpenIdConnect/Models/ConfigurationModel.cs b/src/Plugins/Authentication.OpenIdConnect/Models/ConfigurationModel.cs deleted file mode 100644 index be0d88793..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/Models/ConfigurationModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Grand.Infrastructure.ModelBinding; -using Grand.Infrastructure.Models; - -namespace Authentication.OpenIdConnect.Models; - -public class ConfigurationModel : BaseModel -{ - [GrandResourceDisplayName("Plugins.ExternalAuth.OpenIdConnect.Authority")] - public string Authority { get; set; } - - [GrandResourceDisplayName("Plugins.ExternalAuth.OpenIdConnect.ClientId")] - public string ClientId { get; set; } - - /// Only whether a secret is configured, never the secret itself - [GrandResourceDisplayName("Plugins.ExternalAuth.OpenIdConnect.ClientSecret")] - public string ClientSecret { get; set; } - - [GrandResourceDisplayName("Plugins.ExternalAuth.OpenIdConnect.DisplayOrder")] - public int DisplayOrder { get; set; } -} diff --git a/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs b/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs index 5cbc5b92a..d98b49cfd 100644 --- a/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs +++ b/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs @@ -1,4 +1,3 @@ -using Grand.Business.Core.Interfaces.Common.Configuration; using Grand.Business.Core.Interfaces.Common.Localization; using Grand.Infrastructure.Plugins; using Grand.Web.Common.Security.Oidc; @@ -8,9 +7,7 @@ namespace Authentication.OpenIdConnect; /// /// Sign-in with an OpenID Connect identity provider /// -public class OidcLoginPlugin( - ISettingService settingService, - IPluginTranslateResource pluginTranslateResource) +public class OidcLoginPlugin(IPluginTranslateResource pluginTranslateResource) : BasePlugin, IPlugin { private const string Prefix = "Plugins.ExternalAuth.OpenIdConnect."; @@ -39,21 +36,7 @@ private static readonly (string Key, string Value)[] Resources = [ ("Failed.EmailNotVerified", "Your identity provider has not verified your e-mail address. Verify it there, then sign in again."), ("Failed.ProviderChanged", - "Signing in with the identity provider is paused while the administrator updates the store's connection to it. Try again later."), - ("DisplayOrder", "Display order"), - ("ClientId", "Client ID"), - ("ClientSecret", "Client secret"), - ("ClientSecret.Set", "set"), - ("ClientSecret.NotSet", "not set"), - ("Authority", "Identity provider (Authority)"), - ("Description", - "

The identity provider and the client are configured in the application settings file (appsettings), not here: " + - "section OidcResourceServer holds the identity provider (Authority), " + - "section OidcLogin holds the client of this store (ClientId, ClientSecret, Scopes).

" + - "

Register this redirect URI at the identity provider for every URL of the store: " + - "https://<store-url>/signin-oidc.

" + - "

Restart the application after changing the settings. Staff accounts connect once with their password; " + - "use the multi-factor authentication of the identity provider for them.

") + "Signing in with the identity provider is paused while the administrator updates the store's connection to it. Try again later.") ]; /// @@ -66,9 +49,6 @@ public override string ConfigurationUrl() public override async Task Install() { - //settings - await settingService.SaveSetting(new OidcLoginSettings()); - //locales foreach (var (key, value) in Resources) await pluginTranslateResource.AddOrUpdatePluginTranslateResource(Prefix + key, value); @@ -78,9 +58,6 @@ public override async Task Install() public override async Task Uninstall() { - //settings - await settingService.DeleteSetting(); - //locales foreach (var (key, _) in Resources) await pluginTranslateResource.DeletePluginTranslationResource(Prefix + key); diff --git a/src/Plugins/Authentication.OpenIdConnect/OidcLoginSettings.cs b/src/Plugins/Authentication.OpenIdConnect/OidcLoginSettings.cs deleted file mode 100644 index 76fba5c93..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/OidcLoginSettings.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Grand.Domain.Configuration; - -namespace Authentication.OpenIdConnect; - -public class OidcLoginSettings : ISettings -{ - public int DisplayOrder { get; set; } -} diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/ExternalAuthenticationControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/ExternalAuthenticationControllerTests.cs new file mode 100644 index 000000000..24e1e96ee --- /dev/null +++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/ExternalAuthenticationControllerTests.cs @@ -0,0 +1,57 @@ +using Grand.Business.Core.Interfaces.Authentication; +using Grand.Business.Core.Interfaces.Common.Configuration; +using Grand.Domain.Customers; +using Grand.Infrastructure.Configuration; +using Grand.Web.Admin.Controllers; +using Grand.Web.AdminShared.Models.ExternalAuthentication; +using Microsoft.AspNetCore.Mvc; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Grand.Web.Admin.Tests.Controllers; + +[TestClass] +public class ExternalAuthenticationControllerTests +{ + private const string Authority = "https://idp.test"; + + private static async Task Methods(bool resourceServerEnabled, string clientSecret) + { + var linkService = new Mock(); + linkService.Setup(x => x.GetState()).ReturnsAsync(new OidcLinkState(Authority, Authority, 3)); + var controller = new ExternalAuthenticationController(new Mock().Object, + new ExternalAuthenticationSettings(), new Mock().Object, new Mock().Object); + + return await controller.Methods( + new OidcResourceServerConfig { Enabled = resourceServerEnabled, Authority = Authority }, + new OidcLoginConfig { ClientId = "shop", ClientSecret = clientSecret }, + linkService.Object); + } + + [TestMethod] + public async Task Methods_Configured_ShowsClientIdAndWhetherASecretIsSet() + { + var model = (OidcLinksModel)((ViewResult)await Methods(true, "s3cr3t")).Model!; + + Assert.AreEqual(Authority, model.ConfiguredAuthority); + Assert.AreEqual("shop", model.ClientId); + Assert.IsTrue(model.ClientSecretSet); + //the secret itself never reaches the page + foreach (var property in typeof(OidcLinksModel).GetProperties().Where(x => x.PropertyType == typeof(string))) + Assert.IsFalse(((string)property.GetValue(model))?.Contains("s3cr3t") ?? false, property.Name); + } + + [TestMethod] + public async Task Methods_SecretEmpty_ReportsNoSecret() + { + var model = (OidcLinksModel)((ViewResult)await Methods(true, "")).Model!; + + Assert.IsFalse(model.ClientSecretSet); + } + + [TestMethod] + public async Task Methods_ResourceServerDisabled_ReturnsViewWithoutModel() + { + Assert.IsNull(((ViewResult)await Methods(false, "s3cr3t")).Model); + } +} diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml index 08d01c76d..9af822f46 100644 --- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml +++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml @@ -38,6 +38,31 @@ + @* the identity provider and the client come from appsettings and are shown read-only; the secret is never shown *@ + @if (Model != null) + { + +
+ @Html.Raw(Loc["Admin.Plugins.ExternalAuthenticationMethods.Oidc.Description"]) +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ } + @* the OpenID Connect account links belong to one identity provider: a subject is unique only there *@ @if (Model != null) { diff --git a/src/Web/Grand.Web.Admin/Controllers/ExternalAuthenticationController.cs b/src/Web/Grand.Web.Admin/Controllers/ExternalAuthenticationController.cs index 079c5a5a6..59f506f4b 100644 --- a/src/Web/Grand.Web.Admin/Controllers/ExternalAuthenticationController.cs +++ b/src/Web/Grand.Web.Admin/Controllers/ExternalAuthenticationController.cs @@ -44,9 +44,9 @@ public ExternalAuthenticationController(IExternalAuthenticationService openAuthe #region Methods public async Task Methods([FromServices] OidcResourceServerConfig resourceServerConfig, - [FromServices] IOidcLinkService linkService) + [FromServices] OidcLoginConfig loginConfig, [FromServices] IOidcLinkService linkService) { - //the account links of the OpenID Connect provider, only while it is configured + //the OpenID Connect sign-in and its account links, only while the provider is configured if (!ResourceServerConfigured(resourceServerConfig)) return View(); @@ -56,7 +56,9 @@ public async Task Methods([FromServices] OidcResourceServerConfig LinkedAuthority = state.LinkedAuthority, LinkCount = state.LinkCount, ProviderChanged = state.ProviderChanged, - ProviderUnknown = state.ProviderUnknown + ProviderUnknown = state.ProviderUnknown, + ClientId = loginConfig.ClientId, + ClientSecretSet = !string.IsNullOrWhiteSpace(loginConfig.ClientSecret) }); } diff --git a/src/Web/Grand.Web.AdminShared/Models/ExternalAuthentication/OidcLinksModel.cs b/src/Web/Grand.Web.AdminShared/Models/ExternalAuthentication/OidcLinksModel.cs index 4aa57d70b..8ab8a132f 100644 --- a/src/Web/Grand.Web.AdminShared/Models/ExternalAuthentication/OidcLinksModel.cs +++ b/src/Web/Grand.Web.AdminShared/Models/ExternalAuthentication/OidcLinksModel.cs @@ -8,4 +8,10 @@ public class OidcLinksModel public long LinkCount { get; set; } public bool ProviderChanged { get; set; } public bool ProviderUnknown { get; set; } + + /// OidcLogin:ClientId of the browser sign-in + public string ClientId { get; set; } + + /// Only whether OidcLogin:ClientSecret is set, never the secret itself + public bool ClientSecretSet { get; set; } } diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml index 82316f2f3ae7d460068ec246aa6cd05cd7801fc3..69e978ca1c4d286c16546080f9a8cedf0745f714 100644 GIT binary patch delta 1357 zcma)5O;1x%5S^A%X#1e;E6}1LK8TP)Xd4m}L(yP`g+!uJAkl?MYiUc9e%V$HaRDaR zxM5=&nXMYs#07qYAHhydNZhz_<Qr*H_Ta0yLxiEiN*9^n9yTUy)^rWoC&Dy{JI zJ@+*4ZfQgO?6qd|Hm<2iWy&I9mEV7~EGdvXOf!_jZHfwr%<-Ma?URn?1y6i--c*VH zgNX|OBvCHKgBNX+y-ffaRB493by@2yr;Y)GF-$1Mu`%me{xIgap}2l9^?cWT#?Hs+Ob@L^g zC%`?IJM?54j^q>~NC_(8lU-HuW#Ll>r%@V5y@C>BsOm6-qRswgW)X3NMo_6rQ{XPr zGIBj_-NVCXFmgBy;0gdaKq~xjTZ^m(&GF*8F~^3Ay5s+3q^r=h45E2d$f!>K ziyl(oU!St$pn*k7^Ypx@KNdW=MPQNcv~Cur3})$3RmB!m!zG-hmtp?0p%2WIOmpZu z0#afH=_$aJ1a&r4k!Ads#gd2{w1oUQ{3fWXyz-@$M+Oq^DflWG{2`Q25!t<9hX9{kza&-Ry^K45^b00z0~ z_dzYUzHVHKvbEUPUdt3;d(`7|Wpxq=IiE-ZSAzz^sWA0@<-Jz@{?V= z&xOI8l{t2y&(GWA9{ZX>w+T)kYw*$ii_$D~R$y`t9j;CI;jBrbA-?noU N;em`N#F{H`;t$99Co2E| delta 62 zcmV~$xe#!hqzdK(?-YHO&RMa%IbZ88MrDtGd RVrIdy;@JpKv~s>7rXQV+6Kwzh diff --git a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml index 503982d63..f9e4cab24 100644 --- a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml +++ b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml @@ -66,4 +66,22 @@ Registration of new customers is disabled, so this external account cannot be used to create one. + + Identity provider (Authority) + + + Client ID + + + Client secret + + + set + + + not set + + + <p>The identity provider and the client are configured in the application settings file (appsettings), not here: section <code>OidcResourceServer</code> holds the identity provider (Authority), section <code>OidcLogin</code> holds the client of this store (ClientId, ClientSecret, Scopes).</p><p>Register this redirect URI at the identity provider for every URL of the store: <code>https://&lt;store-url&gt;/signin-oidc</code>.</p><p>Restart the application after changing the settings. Staff accounts connect once with their password; use the multi-factor authentication of the identity provider for them.</p><p>The order of the button is set by <code>OidcLogin:DisplayOrder</code>.</p> + From 97be8fbaef01392eb82d4eb1a6af801898c8c8f3 Mon Sep 17 00:00:00 2001 From: support Date: Thu, 22 Oct 2026 22:46:53 +0200 Subject: [PATCH 3/8] Build the OpenID Connect sign-in into the storefront and remove its plugin --- GrandNode.slnx | 1 - .../Services/OidcSignInModeCheck.cs | 8 +-- .../Services/OidcSsoSignInPolicy.cs | 4 +- .../Startup/StartupApplication.cs | 3 +- .../Authentication/IOidcTokenRefresher.cs | 2 +- .../Authentication.OpenIdConnect.csproj | 18 ----- .../Authentication.OpenIdConnect/Manifest.cs | 10 --- .../OidcLoginPlugin.cs | 67 ------------------ .../Views/OidcLogin/Failed.cshtml | 27 ------- .../Views/OidcLogin/Link.cshtml | 11 --- .../Views/_ViewImports.cshtml | 9 --- .../Services/OidcSessionServiceTests.cs | 2 +- .../Services/OidcSignInModeCheckTests.cs | 18 +---- .../Grand.Modules.Tests.csproj | 1 - .../Middleware/ContextMiddlewareTests.cs | 2 +- .../Security/Oidc/OidcProviderNameTests.cs | 2 +- .../Controllers}/OidcLoginControllerTests.cs | 23 +++--- .../OidcLoginEndpointProviderTests.cs | 40 +++++++++++ .../Security/Oidc/OidcLoginProvider.cs | 2 +- .../Oidc/OidcResourceServerDefaults.cs | 2 +- .../Customer/OidcFailedModel.cs} | 4 +- .../Customer/OidcLinkModel.cs} | 4 +- .../App_Data/Resources/DefaultLanguage.xml | Bin 1578964 -> 1584344 bytes .../App_Data/Resources/Upgrade/en_250.xml | 45 ++++++++++++ src/Web/Grand.Web/App_Data/appsettings.json | 2 +- .../Components/OidcLoginViewComponent.cs | 2 +- .../Controllers/OidcLoginController.cs | 12 ++-- .../Endpoints/OidcLoginEndpointProvider.cs} | 7 +- .../Grand.Web/Views/OidcLogin/Failed.cshtml | 27 +++++++ src/Web/Grand.Web/Views/OidcLogin/Link.cshtml | 11 +++ .../Components/OidcLogin/Default.cshtml | 2 +- 31 files changed, 165 insertions(+), 203 deletions(-) delete mode 100644 src/Plugins/Authentication.OpenIdConnect/Authentication.OpenIdConnect.csproj delete mode 100644 src/Plugins/Authentication.OpenIdConnect/Manifest.cs delete mode 100644 src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs delete mode 100644 src/Plugins/Authentication.OpenIdConnect/Views/OidcLogin/Failed.cshtml delete mode 100644 src/Plugins/Authentication.OpenIdConnect/Views/OidcLogin/Link.cshtml delete mode 100644 src/Plugins/Authentication.OpenIdConnect/Views/_ViewImports.cshtml rename src/Tests/{Grand.Modules.Tests/Plugins/OpenIdConnect => Grand.Web.Tests/Controllers}/OidcLoginControllerTests.cs (98%) create mode 100644 src/Tests/Grand.Web.Tests/Endpoints/OidcLoginEndpointProviderTests.cs rename src/{Plugins/Authentication.OpenIdConnect/Models/FailedModel.cs => Web/Grand.Web.Models/Customer/OidcFailedModel.cs} (89%) rename src/{Plugins/Authentication.OpenIdConnect/Models/LinkModel.cs => Web/Grand.Web.Models/Customer/OidcLinkModel.cs} (54%) rename src/{Plugins/Authentication.OpenIdConnect => Web/Grand.Web}/Components/OidcLoginViewComponent.cs (92%) rename src/{Plugins/Authentication.OpenIdConnect => Web/Grand.Web}/Controllers/OidcLoginController.cs (97%) rename src/{Plugins/Authentication.OpenIdConnect/EndpointProvider.cs => Web/Grand.Web/Endpoints/OidcLoginEndpointProvider.cs} (86%) create mode 100644 src/Web/Grand.Web/Views/OidcLogin/Failed.cshtml create mode 100644 src/Web/Grand.Web/Views/OidcLogin/Link.cshtml rename src/{Plugins/Authentication.OpenIdConnect => Web/Grand.Web}/Views/Shared/Components/OidcLogin/Default.cshtml (71%) diff --git a/GrandNode.slnx b/GrandNode.slnx index 66e9c3af4..efa35892c 100644 --- a/GrandNode.slnx +++ b/GrandNode.slnx @@ -37,7 +37,6 @@ - diff --git a/src/Business/Grand.Business.Authentication/Services/OidcSignInModeCheck.cs b/src/Business/Grand.Business.Authentication/Services/OidcSignInModeCheck.cs index d6c25d596..c36510fea 100644 --- a/src/Business/Grand.Business.Authentication/Services/OidcSignInModeCheck.cs +++ b/src/Business/Grand.Business.Authentication/Services/OidcSignInModeCheck.cs @@ -1,5 +1,4 @@ using Grand.Infrastructure.Configuration; -using Grand.Infrastructure.Plugins; namespace Grand.Business.Authentication.Services; @@ -9,17 +8,12 @@ namespace Grand.Business.Authentication.Services; ///
public static class OidcSignInModeCheck { - public static string Problem(OidcLoginConfig config, OidcResourceServerConfig resourceServer, - IEnumerable plugins) + public static string Problem(OidcLoginConfig config, OidcResourceServerConfig resourceServer) { if (config is not { ProviderOnly: true }) return null; if (!config.IsConfigured(resourceServer)) return "OidcResourceServer:Authority or OidcLogin:ClientId is empty"; - if (plugins?.Any(x => x.Installed && - string.Equals(x.SystemName, OidcCustomerResolver.ProviderSystemName, - StringComparison.OrdinalIgnoreCase)) != true) - return "the OpenID Connect login plugin is not installed"; return null; } } diff --git a/src/Business/Grand.Business.Authentication/Services/OidcSsoSignInPolicy.cs b/src/Business/Grand.Business.Authentication/Services/OidcSsoSignInPolicy.cs index 3a0f8457e..c911342a4 100644 --- a/src/Business/Grand.Business.Authentication/Services/OidcSsoSignInPolicy.cs +++ b/src/Business/Grand.Business.Authentication/Services/OidcSsoSignInPolicy.cs @@ -81,7 +81,7 @@ private void LogUnavailable() if (memoryCache.TryGetValue(UnavailableLogKey, out _)) return; memoryCache.Set(UnavailableLogKey, true, TimeSpan.FromMinutes(5)); - logger.LogError("ProviderOnly sign-in mode without a working OpenID Connect login (plugin not installed, " + - "not active or not configured): only break-glass accounts can sign in"); + logger.LogError("ProviderOnly sign-in mode without a working OpenID Connect login (not configured or not " + + "active): only break-glass accounts can sign in"); } } diff --git a/src/Business/Grand.Business.Authentication/Startup/StartupApplication.cs b/src/Business/Grand.Business.Authentication/Startup/StartupApplication.cs index 1463a5638..019a59241 100644 --- a/src/Business/Grand.Business.Authentication/Startup/StartupApplication.cs +++ b/src/Business/Grand.Business.Authentication/Startup/StartupApplication.cs @@ -2,7 +2,6 @@ using Grand.Business.Core.Interfaces.Authentication; using Grand.Infrastructure; using Grand.Infrastructure.Configuration; -using Grand.Infrastructure.Plugins; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -32,7 +31,7 @@ public void ConfigureServices(IServiceCollection services, IConfiguration config public void Configure(WebApplication application, IWebHostEnvironment webHostEnvironment) { var problem = OidcSignInModeCheck.Problem(application.Services.GetService(), - application.Services.GetService(), PluginManager.ReferencedPlugins); + application.Services.GetService()); if (problem != null) application.Services.GetRequiredService>().LogError( "ProviderOnly sign-in mode without a working OpenID Connect login ({Problem}): only break-glass accounts can sign in", diff --git a/src/Business/Grand.Business.Core/Interfaces/Authentication/IOidcTokenRefresher.cs b/src/Business/Grand.Business.Core/Interfaces/Authentication/IOidcTokenRefresher.cs index fee3d1ac2..f7234610e 100644 --- a/src/Business/Grand.Business.Core/Interfaces/Authentication/IOidcTokenRefresher.cs +++ b/src/Business/Grand.Business.Core/Interfaces/Authentication/IOidcTokenRefresher.cs @@ -3,7 +3,7 @@ namespace Grand.Business.Core.Interfaces.Authentication; /// -/// Exchanges a refresh token at the identity provider (implemented by the OpenID Connect login plugin; with no +/// Exchanges a refresh token at the identity provider (registered while the OpenID Connect sign-in is configured; with no /// implementation registered a session cannot be confirmed and ends) /// public interface IOidcTokenRefresher diff --git a/src/Plugins/Authentication.OpenIdConnect/Authentication.OpenIdConnect.csproj b/src/Plugins/Authentication.OpenIdConnect/Authentication.OpenIdConnect.csproj deleted file mode 100644 index 8aded22b6..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/Authentication.OpenIdConnect.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - - true - false - - - ..\..\Web\Grand.Web\Plugins\Authentication.OpenIdConnect - $(OutputPath) - - - - ..\..\Web\Grand.Web\Plugins\Authentication.OpenIdConnect - $(OutputPath) - - - diff --git a/src/Plugins/Authentication.OpenIdConnect/Manifest.cs b/src/Plugins/Authentication.OpenIdConnect/Manifest.cs deleted file mode 100644 index 5153a8b87..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/Manifest.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Grand.Web.Common.Security.Oidc; -using Grand.Infrastructure.Plugins; - -[assembly: PluginInfo( - FriendlyName = "OpenID Connect", - Group = "Authentication methods", - SystemName = OidcLoginDefaults.ProviderSystemName, - Author = "grandnode team", - Version = "2.5.0" -)] diff --git a/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs b/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs deleted file mode 100644 index d98b49cfd..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/OidcLoginPlugin.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Grand.Business.Core.Interfaces.Common.Localization; -using Grand.Infrastructure.Plugins; -using Grand.Web.Common.Security.Oidc; - -namespace Authentication.OpenIdConnect; - -/// -/// Sign-in with an OpenID Connect identity provider -/// -public class OidcLoginPlugin(IPluginTranslateResource pluginTranslateResource) - : BasePlugin, IPlugin -{ - private const string Prefix = "Plugins.ExternalAuth.OpenIdConnect."; - - private static readonly (string Key, string Value)[] Resources = [ - ("Login", "Sign in with your organization account"), - ("Link.Title", "Connect your account"), - ("Link.Text", - "An account with the e-mail {0} already exists in this store. Sign in once with its password to connect it; next time the button is enough."), - ("Link.SignIn", "Sign in with password"), - ("Link.Mismatch", - "You are signed in with a different e-mail address than the one from your identity provider. Nothing was connected."), - ("Failed.Title", "Sign-in failed"), - ("Failed.Generic", - "Signing in with the identity provider did not succeed. Try again or use another sign-in method."), - ("Failed.AccountInactive", - "Your account is not active yet. Use the activation link from the e-mail or wait for approval."), - ("Failed.RegistrationDisabled", "New accounts cannot be registered in this store."), - ("Failed.LinkedToOtherIdentity", "This account is already connected to another identity provider account."), - ("Failed.IdentityLinkedToOtherAccount", - "Your identity provider account is already connected to another account in this store. Nothing was connected."), - ("Failed.SignedInAsOtherAccount", - "You are already signed in with another account. Sign out first, then sign in with your identity provider."), - ("Failed.SessionUnavailable", - "Signing in with the identity provider is not set up completely. Use another sign-in method, or ask the administrator."), - ("Failed.EmailNotVerified", - "Your identity provider has not verified your e-mail address. Verify it there, then sign in again."), - ("Failed.ProviderChanged", - "Signing in with the identity provider is paused while the administrator updates the store's connection to it. Try again later.") - ]; - - /// - /// Gets a configuration page URL - /// - public override string ConfigurationUrl() - { - return OidcLoginDefaults.ConfigurationUrl; - } - - public override async Task Install() - { - //locales - foreach (var (key, value) in Resources) - await pluginTranslateResource.AddOrUpdatePluginTranslateResource(Prefix + key, value); - - await base.Install(); - } - - public override async Task Uninstall() - { - //locales - foreach (var (key, _) in Resources) - await pluginTranslateResource.DeletePluginTranslationResource(Prefix + key); - - await base.Uninstall(); - } -} diff --git a/src/Plugins/Authentication.OpenIdConnect/Views/OidcLogin/Failed.cshtml b/src/Plugins/Authentication.OpenIdConnect/Views/OidcLogin/Failed.cshtml deleted file mode 100644 index 8c48673fb..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/Views/OidcLogin/Failed.cshtml +++ /dev/null @@ -1,27 +0,0 @@ -@using Grand.Business.Core.Utilities.Authentication -@model Authentication.OpenIdConnect.Models.FailedModel -@{ - Layout = "_SingleColumn"; - var key = Model.Mismatch - ? "Plugins.ExternalAuth.OpenIdConnect.Link.Mismatch" - : Model.IdentityTaken - ? "Plugins.ExternalAuth.OpenIdConnect.Failed.IdentityLinkedToOtherAccount" - : Model.SignedInAsOtherAccount - ? "Plugins.ExternalAuth.OpenIdConnect.Failed.SignedInAsOtherAccount" - : Model.SessionUnavailable - ? "Plugins.ExternalAuth.OpenIdConnect.Failed.SessionUnavailable" - : Model.Reason switch { - OidcLoginRefusal.AccountInactive => "Plugins.ExternalAuth.OpenIdConnect.Failed.AccountInactive", - OidcLoginRefusal.RegistrationDisabled => "Plugins.ExternalAuth.OpenIdConnect.Failed.RegistrationDisabled", - OidcLoginRefusal.LinkedToOtherIdentity => "Plugins.ExternalAuth.OpenIdConnect.Failed.LinkedToOtherIdentity", - OidcLoginRefusal.EmailNotVerified => "Plugins.ExternalAuth.OpenIdConnect.Failed.EmailNotVerified", - OidcLoginRefusal.ProviderChanged => "Plugins.ExternalAuth.OpenIdConnect.Failed.ProviderChanged", - _ => "Plugins.ExternalAuth.OpenIdConnect.Failed.Generic" - }; -} -
-

@Loc["Plugins.ExternalAuth.OpenIdConnect.Failed.Title"]

-
-
@Loc[key]
-
-
diff --git a/src/Plugins/Authentication.OpenIdConnect/Views/OidcLogin/Link.cshtml b/src/Plugins/Authentication.OpenIdConnect/Views/OidcLogin/Link.cshtml deleted file mode 100644 index 4bf726480..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/Views/OidcLogin/Link.cshtml +++ /dev/null @@ -1,11 +0,0 @@ -@model Authentication.OpenIdConnect.Models.LinkModel -@{ - Layout = "_SingleColumn"; -} - diff --git a/src/Plugins/Authentication.OpenIdConnect/Views/_ViewImports.cshtml b/src/Plugins/Authentication.OpenIdConnect/Views/_ViewImports.cshtml deleted file mode 100644 index 64b90fbf3..000000000 --- a/src/Plugins/Authentication.OpenIdConnect/Views/_ViewImports.cshtml +++ /dev/null @@ -1,9 +0,0 @@ -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers -@addTagHelper *, Grand.Web.Common - -@using Microsoft.AspNetCore.Mvc.ViewFeatures -@using Grand.Infrastructure.Extensions -@using Grand.Web.Common.Extensions -@using Grand.Web.Common.Localization - -@inject LocService Loc \ No newline at end of file diff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/OidcSessionServiceTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/OidcSessionServiceTests.cs index d66faca92..d013020da 100644 --- a/src/Tests/Grand.Business.Authentication.Tests/Services/OidcSessionServiceTests.cs +++ b/src/Tests/Grand.Business.Authentication.Tests/Services/OidcSessionServiceTests.cs @@ -480,7 +480,7 @@ public async Task Validate_RefresherCancelled_TreatedAsUnavailable() Assert.IsNull(Stored(session.Id).EndedUtc); } - //the login plugin was uninstalled: every session ends at the next check + //the OpenID Connect sign-in is no longer configured: every session ends at the next check [TestMethod] public async Task NoRefresher_CountsAsRefused() { diff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/OidcSignInModeCheckTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/OidcSignInModeCheckTests.cs index 79f7d5eeb..24d6fd8d7 100644 --- a/src/Tests/Grand.Business.Authentication.Tests/Services/OidcSignInModeCheckTests.cs +++ b/src/Tests/Grand.Business.Authentication.Tests/Services/OidcSignInModeCheckTests.cs @@ -1,6 +1,5 @@ using Grand.Business.Authentication.Services; using Grand.Infrastructure.Configuration; -using Grand.Infrastructure.Plugins; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Grand.Business.Authentication.Tests.Services; @@ -10,28 +9,17 @@ public class OidcSignInModeCheckTests { private readonly OidcResourceServerConfig _resourceServer = new() { Authority = "https://idp" }; - private static PluginInfo[] Plugin(bool installed) => - [new PluginInfo { SystemName = OidcCustomerResolver.ProviderSystemName, Installed = installed }]; - [TestMethod] public void Mixed_NeverAProblem() => - Assert.IsNull(OidcSignInModeCheck.Problem(new OidcLoginConfig(), new OidcResourceServerConfig(), [])); + Assert.IsNull(OidcSignInModeCheck.Problem(new OidcLoginConfig(), new OidcResourceServerConfig())); [TestMethod] public void ProviderOnly_Working_NoProblem() => Assert.IsNull(OidcSignInModeCheck.Problem( - new OidcLoginConfig { SignInMode = OidcSignInMode.ProviderOnly, ClientId = "shop" }, _resourceServer, Plugin(true))); + new OidcLoginConfig { SignInMode = OidcSignInMode.ProviderOnly, ClientId = "shop" }, _resourceServer)); [TestMethod] public void ProviderOnly_NotConfigured_Problem() => Assert.IsNotNull(OidcSignInModeCheck.Problem( - new OidcLoginConfig { SignInMode = OidcSignInMode.ProviderOnly }, _resourceServer, Plugin(true))); - - [TestMethod] - public void ProviderOnly_PluginNotInstalled_Problem() - { - var config = new OidcLoginConfig { SignInMode = OidcSignInMode.ProviderOnly, ClientId = "shop" }; - Assert.IsNotNull(OidcSignInModeCheck.Problem(config, _resourceServer, Plugin(false))); - Assert.IsNotNull(OidcSignInModeCheck.Problem(config, _resourceServer, null)); - } + new OidcLoginConfig { SignInMode = OidcSignInMode.ProviderOnly }, _resourceServer)); } diff --git a/src/Tests/Grand.Modules.Tests/Grand.Modules.Tests.csproj b/src/Tests/Grand.Modules.Tests/Grand.Modules.Tests.csproj index 78bfcc9de..b9b154255 100644 --- a/src/Tests/Grand.Modules.Tests/Grand.Modules.Tests.csproj +++ b/src/Tests/Grand.Modules.Tests/Grand.Modules.Tests.csproj @@ -22,7 +22,6 @@ - diff --git a/src/Tests/Grand.Web.Common.Tests/Middleware/ContextMiddlewareTests.cs b/src/Tests/Grand.Web.Common.Tests/Middleware/ContextMiddlewareTests.cs index ede80d184..5d1f1a132 100644 --- a/src/Tests/Grand.Web.Common.Tests/Middleware/ContextMiddlewareTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Middleware/ContextMiddlewareTests.cs @@ -64,7 +64,7 @@ public async Task RouteOnlyPrefixedByMetadataPath_InitializesStoreAndWorkContext _workContextSetter.Verify(x => x.InitializeWorkContext("store1"), Times.Once); } - //a server-to-server endpoint (for example the back-channel logout of the login plugin) creates no guest + //a server-to-server endpoint (for example the OpenID Connect back-channel logout) creates no guest [TestMethod] public async Task NoRequestContextMetadata_NoStoreOrWorkContext() { diff --git a/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcProviderNameTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcProviderNameTests.cs index 337be6152..9af8097d1 100644 --- a/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcProviderNameTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcProviderNameTests.cs @@ -7,7 +7,7 @@ namespace Grand.Web.Common.Tests.Security.Oidc; [TestClass] public class OidcProviderNameTests { - //the link written by the resolver must be the one the web layer and the login plugin look up + //the link written by the resolver must be the one the web layer and the OpenID Connect sign-in look up [TestMethod] public void ResolverAndWebDefaults_UseTheSameLinkName() => Assert.AreEqual(OidcCustomerResolver.ProviderSystemName, OidcResourceServerDefaults.ProviderSystemName); diff --git a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginControllerTests.cs b/src/Tests/Grand.Web.Tests/Controllers/OidcLoginControllerTests.cs similarity index 98% rename from src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginControllerTests.cs rename to src/Tests/Grand.Web.Tests/Controllers/OidcLoginControllerTests.cs index 211f09e79..eb72fbe98 100644 --- a/src/Tests/Grand.Modules.Tests/Plugins/OpenIdConnect/OidcLoginControllerTests.cs +++ b/src/Tests/Grand.Web.Tests/Controllers/OidcLoginControllerTests.cs @@ -1,21 +1,20 @@ -using Authentication.OpenIdConnect; -using Authentication.OpenIdConnect.Controllers; -using Authentication.OpenIdConnect.Models; -using Grand.Business.Core.Interfaces.Customers; -using Grand.Infrastructure.Configuration; using Grand.Business.Core.Events.Customers; using Grand.Business.Core.Interfaces.Authentication; using Grand.Business.Core.Interfaces.Common.Directory; +using Grand.Business.Core.Interfaces.Customers; using Grand.Business.Core.Utilities.Authentication; using Grand.Domain.Common; using Grand.Domain.Customers; using Grand.Domain.Localization; using Grand.Domain.Stores; +using Grand.Infrastructure.Configuration; using Grand.Infrastructure; using Grand.Mediator; using Grand.Web.Common.Security.Authentication; using Grand.Web.Common.Security.ExternalRegistration; using Grand.Web.Common.Security.Oidc; +using Grand.Web.Controllers; +using Grand.Web.Models.Customer; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -27,7 +26,7 @@ using System.Globalization; using System.Security.Claims; -namespace Grand.Modules.Tests.Plugins.OpenIdConnect; +namespace Grand.Web.Tests.Controllers; [TestClass] public class OidcLoginControllerTests @@ -90,7 +89,7 @@ public void Init() work.Setup(x => x.CurrentCustomer).Returns(() => _current); work.Setup(x => x.WorkingLanguage).Returns(Language); var store = new Mock(); - store.Setup(x => x.CurrentStore).Returns(new Store { Id = "s1" }); + store.Setup(x => x.CurrentStore).Returns(new Grand.Domain.Stores.Store { Id = "s1" }); var ctx = new Mock(); ctx.Setup(x => x.WorkContext).Returns(work.Object); ctx.Setup(x => x.StoreContext).Returns(store.Object); @@ -146,7 +145,7 @@ public async Task Login_NotConfigured_Failed() Assert.AreEqual("OidcLoginFailed", ((RedirectToRouteResult)await _controller.Login("/")).RouteName); _logger.Verify(x => x.Log(LogLevel.Warning, It.IsAny(), It.Is((v, _) => v.ToString()!.Contains( - "or the application was not restarted after the plugin was installed")), + "or the application was not restarted after the settings changed")), It.IsAny(), It.IsAny>()), Times.Once); } @@ -282,7 +281,7 @@ public async Task LinkComplete_CustomerLinkedToOtherSubject_FailedWithLinkedToOt [TestMethod] public void Failed_IdentityTaken_InModel() { - var model = (FailedModel)((ViewResult)_controller.Failed(null, taken: true)).Model!; + var model = (OidcFailedModel)((ViewResult)_controller.Failed(null, taken: true)).Model!; Assert.IsTrue(model.IdentityTaken); } @@ -414,7 +413,7 @@ public async Task LinkComplete_TicketIssuedInSameSecondAsLink_Links() [TestMethod] public void Failed_SignedIn_InModel() { - var model = (FailedModel)((ViewResult)_controller.Failed(null, signedIn: true)).Model!; + var model = (OidcFailedModel)((ViewResult)_controller.Failed(null, signedIn: true)).Model!; Assert.IsTrue(model.SignedInAsOtherAccount); } @@ -496,7 +495,7 @@ public async Task Callback_SessionNotStarted_FailedPage_NotSignedIn() [TestMethod] public void Failed_SessionUnavailable_Model() { - var model = (FailedModel)((ViewResult)_controller.Failed(null, session: true)).Model!; + var model = (OidcFailedModel)((ViewResult)_controller.Failed(null, session: true)).Model!; Assert.IsTrue(model.SessionUnavailable); } @@ -654,7 +653,7 @@ public async Task LinkComplete_ProviderOnly_Failed() [TestMethod] public void Failed_EmailNotVerified_ShowsText() { - var model = (FailedModel)((ViewResult)_controller.Failed((int)OidcLoginRefusal.EmailNotVerified)).Model!; + var model = (OidcFailedModel)((ViewResult)_controller.Failed((int)OidcLoginRefusal.EmailNotVerified)).Model!; Assert.AreEqual(OidcLoginRefusal.EmailNotVerified, model.Reason); } } diff --git a/src/Tests/Grand.Web.Tests/Endpoints/OidcLoginEndpointProviderTests.cs b/src/Tests/Grand.Web.Tests/Endpoints/OidcLoginEndpointProviderTests.cs new file mode 100644 index 000000000..2f4b4885c --- /dev/null +++ b/src/Tests/Grand.Web.Tests/Endpoints/OidcLoginEndpointProviderTests.cs @@ -0,0 +1,40 @@ +using Grand.Web.Common.Middleware; +using Grand.Web.Endpoints; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Grand.Web.Tests.Endpoints; + +[TestClass] +public class OidcLoginEndpointProviderTests +{ + //the identity providers have these addresses registered: they never move, and never get a language prefix + [TestMethod] + public void RegisterEndpoint_RegistersOidcRoutesAtRoot() + { + var builder = WebApplication.CreateBuilder(); + builder.Services.AddControllersWithViews(); + var application = builder.Build(); + + new OidcLoginEndpointProvider().RegisterEndpoint(application); + + var routes = ((IEndpointRouteBuilder)application).DataSources.SelectMany(x => x.Endpoints).OfType() + .ToList(); + var named = routes.Select(x => (x.Metadata.GetMetadata()?.RouteName, x.RoutePattern.RawText)) + .Where(x => x.RouteName != null).ToList(); + CollectionAssert.IsSubsetOf(new[] { + ("OidcLoginLogin", "oidc/login"), + ("OidcLoginCallback", "oidc/callback"), + ("OidcLoginLink", "oidc/link"), + ("OidcLoginLinkComplete", "oidc/link/complete"), + ("OidcLoginFailed", "oidc/failed") + }, named); + + var backChannel = routes.Single(x => x.RoutePattern.RawText == "oidc/backchannel-logout"); + CollectionAssert.AreEqual(new[] { "POST" }, + backChannel.Metadata.GetMetadata()!.HttpMethods.ToArray()); + Assert.IsNotNull(backChannel.Metadata.GetMetadata()); + } +} diff --git a/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginProvider.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginProvider.cs index 2453f203a..7564af17b 100644 --- a/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginProvider.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginProvider.cs @@ -20,7 +20,7 @@ public class OidcLoginProvider(OidcLoginConfig config, IAuthenticationSchemeProv public IList LimitedToGroups => new List(); /// - /// Gets a view component for displaying plugin in public store + /// Gets a view component for displaying the sign-in button in public store /// public Task GetPublicViewComponentName() => Task.FromResult("OidcLogin"); diff --git a/src/Web/Grand.Web.Common/Security/Oidc/OidcResourceServerDefaults.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcResourceServerDefaults.cs index c1d12d30f..dc320c176 100644 --- a/src/Web/Grand.Web.Common/Security/Oidc/OidcResourceServerDefaults.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcResourceServerDefaults.cs @@ -4,7 +4,7 @@ public static class OidcResourceServerDefaults { public const string AuthenticationScheme = "Oidc"; - /// ExternalAuthentication.ProviderSystemName of the link between token subject and customer; also the system name of the OpenID Connect login plugin + /// ExternalAuthentication.ProviderSystemName of the link between token subject and customer; also the system name of the OpenID Connect sign-in method public const string ProviderSystemName = "ExternalAuth.OpenIdConnect"; public const string CustomerItemKey = "Grand.Oidc.Customer"; diff --git a/src/Plugins/Authentication.OpenIdConnect/Models/FailedModel.cs b/src/Web/Grand.Web.Models/Customer/OidcFailedModel.cs similarity index 89% rename from src/Plugins/Authentication.OpenIdConnect/Models/FailedModel.cs rename to src/Web/Grand.Web.Models/Customer/OidcFailedModel.cs index 111bff814..4692dbaba 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Models/FailedModel.cs +++ b/src/Web/Grand.Web.Models/Customer/OidcFailedModel.cs @@ -1,8 +1,8 @@ using Grand.Business.Core.Utilities.Authentication; -namespace Authentication.OpenIdConnect.Models; +namespace Grand.Web.Models.Customer; -public class FailedModel +public class OidcFailedModel { public OidcLoginRefusal Reason { get; set; } public bool Mismatch { get; set; } diff --git a/src/Plugins/Authentication.OpenIdConnect/Models/LinkModel.cs b/src/Web/Grand.Web.Models/Customer/OidcLinkModel.cs similarity index 54% rename from src/Plugins/Authentication.OpenIdConnect/Models/LinkModel.cs rename to src/Web/Grand.Web.Models/Customer/OidcLinkModel.cs index 76807cf82..7faf51592 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Models/LinkModel.cs +++ b/src/Web/Grand.Web.Models/Customer/OidcLinkModel.cs @@ -1,6 +1,6 @@ -namespace Authentication.OpenIdConnect.Models; +namespace Grand.Web.Models.Customer; -public class LinkModel +public class OidcLinkModel { public string Email { get; set; } public string LoginUrl { get; set; } diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml index 69e978ca1c4d286c16546080f9a8cedf0745f714..5ce402301708ce9ceacb141d3c03ff40a4a1d2df 100644 GIT binary patch delta 2034 zcmb7FOKcle6n(bGjy;{k5*83DD_AX!fZP6g{E4BthyfYN!N4>Lv-hf`nLP0UJbx)DNW~b=3s|?wzUAnktd2S&aSO z{hV{|XSUXIKmDAmaTj-U50|)?`*;iY^8lCm9=Zs_HpfcLVm)kx&9DNV^sr%AcZbq&@#A(0M%Oi;c<<)kNSRgH6w9OW3|qvv zh3~RhS`CX0Ypi>hU}#rjr!nj?c%x5Ci{+%RrNoMu$rArc@h5P1m9>Me4Cai84zDa~ zcO>}ou3Lf|YPik&K6{>h0B3KvBw=e&?|3%B#xe60=1$lM5=ga#NsIV@0Z%M8ZQoeT z6v^(0$3iym+%fhY#8ZNI4lNQk%QLnQ*%u-6O1lv#q58n1;k5bpemVI3~J^g!4aQ-5%XZTLOLtQVOh@ICeBHoRq!G6c~o*1dM_#2{X5NVqmE;dkFysTSLohn%@dxv^NcD*~ z#aYDwOAfcg>aZchFN=C%u#xDaOQA9N@B=bb{$q%4#1@r`HiRcdxU#Gt0`+^Z4@RS2 z3I3Rn6|sEHCw}$442Sh-3QlC@cgLH}X2--L($29^2WO!;yJ-R$RAJ@X;db%W delta 62 zcmca{GvUhmgoYNz7N!>F7M2#)7Pc1l7LFFq7OocV7M>Q~7QPn#7J(MQ7NHj57LgXw S7O@ubEfTxLr|;8|kOBa{Bows( diff --git a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml index f9e4cab24..e189511c6 100644 --- a/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml +++ b/src/Web/Grand.Web/App_Data/Resources/Upgrade/en_250.xml @@ -84,4 +84,49 @@ <p>The identity provider and the client are configured in the application settings file (appsettings), not here: section <code>OidcResourceServer</code> holds the identity provider (Authority), section <code>OidcLogin</code> holds the client of this store (ClientId, ClientSecret, Scopes).</p><p>Register this redirect URI at the identity provider for every URL of the store: <code>https://&lt;store-url&gt;/signin-oidc</code>.</p><p>Restart the application after changing the settings. Staff accounts connect once with their password; use the multi-factor authentication of the identity provider for them.</p><p>The order of the button is set by <code>OidcLogin:DisplayOrder</code>.</p> + + Sign in with your organization account + + + Connect your account + + + An account with the e-mail {0} already exists in this store. Sign in once with its password to connect it; next time the button is enough. + + + Sign in with password + + + You are signed in with a different e-mail address than the one from your identity provider. Nothing was connected. + + + Sign-in failed + + + Signing in with the identity provider did not succeed. Try again or use another sign-in method. + + + Your account is not active yet. Use the activation link from the e-mail or wait for approval. + + + New accounts cannot be registered in this store. + + + This account is already connected to another identity provider account. + + + Your identity provider account is already connected to another account in this store. Nothing was connected. + + + You are already signed in with another account. Sign out first, then sign in with your identity provider. + + + Signing in with the identity provider is not set up completely. Use another sign-in method, or ask the administrator. + + + Your identity provider has not verified your e-mail address. Verify it there, then sign in again. + + + Signing in with the identity provider is paused while the administrator updates the store's connection to it. Try again later. + diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json index 9650f07ba..7f7d5a7fa 100644 --- a/src/Web/Grand.Web/App_Data/appsettings.json +++ b/src/Web/Grand.Web/App_Data/appsettings.json @@ -296,7 +296,7 @@ ] }, - //browser sign-in with the identity provider of OidcResourceServer (plugin Authentication.OpenIdConnect). + //browser sign-in with the identity provider of OidcResourceServer (built in: on when OidcResourceServer:Authority and OidcLogin:ClientId are set). //See docs/oidc-resource-server.md, section 11 and 12. "OidcLogin": { "ClientId": "", diff --git a/src/Plugins/Authentication.OpenIdConnect/Components/OidcLoginViewComponent.cs b/src/Web/Grand.Web/Components/OidcLoginViewComponent.cs similarity index 92% rename from src/Plugins/Authentication.OpenIdConnect/Components/OidcLoginViewComponent.cs rename to src/Web/Grand.Web/Components/OidcLoginViewComponent.cs index a6c3d0d9b..7b7182970 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Components/OidcLoginViewComponent.cs +++ b/src/Web/Grand.Web/Components/OidcLoginViewComponent.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Mvc; -namespace Authentication.OpenIdConnect.Components; +namespace Grand.Web.Components; [ViewComponent(Name = "OidcLogin")] public class OidcLoginViewComponent(IAuthenticationSchemeProvider authenticationSchemeProvider) : ViewComponent diff --git a/src/Plugins/Authentication.OpenIdConnect/Controllers/OidcLoginController.cs b/src/Web/Grand.Web/Controllers/OidcLoginController.cs similarity index 97% rename from src/Plugins/Authentication.OpenIdConnect/Controllers/OidcLoginController.cs rename to src/Web/Grand.Web/Controllers/OidcLoginController.cs index 1a55f272d..8cc7d22c1 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Controllers/OidcLoginController.cs +++ b/src/Web/Grand.Web/Controllers/OidcLoginController.cs @@ -1,4 +1,3 @@ -using Authentication.OpenIdConnect.Models; using Grand.Business.Core.Events.Customers; using Grand.Business.Core.Interfaces.Authentication; using Grand.Business.Core.Interfaces.Common.Directory; @@ -10,15 +9,16 @@ using Grand.Web.Common.Security.Authentication; using Grand.Web.Common.Security.ExternalRegistration; using Grand.Web.Common.Security.Oidc; +using Grand.Web.Models.Customer; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System.Globalization; -namespace Authentication.OpenIdConnect.Controllers; +namespace Grand.Web.Controllers; -public class OidcLoginController : BasePluginController +public class OidcLoginController : BaseController { #region Ctor @@ -82,7 +82,7 @@ public async Task Login(string returnUrl) if (await _authenticationSchemeProvider.GetSchemeAsync(OidcLoginDefaults.AuthenticationScheme) == null) { _logger.LogWarning("OpenID Connect login has no sign-in scheme: OidcResourceServer:Authority or " + - "OidcLogin:ClientId is empty, or the application was not restarted after the plugin was installed"); + "OidcLogin:ClientId is empty, or the application was not restarted after the settings changed"); return RedirectToRoute("OidcLoginFailed"); } @@ -188,7 +188,7 @@ public async Task Link(string returnUrl) returnUrl = LocalOrNull(returnUrl); var completeUrl = Url.RouteUrl("OidcLoginLinkComplete", new { returnUrl }); - return View(new LinkModel { + return View(new OidcLinkModel { Email = pending.Email, LoginUrl = Url.RouteUrl("Login", new { returnUrl = completeUrl }) }); @@ -242,7 +242,7 @@ public async Task LinkComplete(string returnUrl) public IActionResult Failed(int? reason, bool mismatch = false, bool taken = false, bool signedIn = false, bool session = false) => - View(new FailedModel { + View(new OidcFailedModel { Reason = (OidcLoginRefusal)(reason ?? 0), Mismatch = mismatch, IdentityTaken = taken, SignedInAsOtherAccount = signedIn, SessionUnavailable = session }); diff --git a/src/Plugins/Authentication.OpenIdConnect/EndpointProvider.cs b/src/Web/Grand.Web/Endpoints/OidcLoginEndpointProvider.cs similarity index 86% rename from src/Plugins/Authentication.OpenIdConnect/EndpointProvider.cs rename to src/Web/Grand.Web/Endpoints/OidcLoginEndpointProvider.cs index f4292f2a0..20067d911 100644 --- a/src/Plugins/Authentication.OpenIdConnect/EndpointProvider.cs +++ b/src/Web/Grand.Web/Endpoints/OidcLoginEndpointProvider.cs @@ -5,9 +5,12 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; -namespace Authentication.OpenIdConnect; +namespace Grand.Web.Endpoints; -public class EndpointProvider : IEndpointProvider +/// +/// OpenID Connect sign-in: fixed addresses registered at the identity providers, never prefixed with a language +/// +public class OidcLoginEndpointProvider : IEndpointProvider { public void RegisterEndpoint(IEndpointRouteBuilder endpointRouteBuilder) { diff --git a/src/Web/Grand.Web/Views/OidcLogin/Failed.cshtml b/src/Web/Grand.Web/Views/OidcLogin/Failed.cshtml new file mode 100644 index 000000000..7f81dc3aa --- /dev/null +++ b/src/Web/Grand.Web/Views/OidcLogin/Failed.cshtml @@ -0,0 +1,27 @@ +@using Grand.Business.Core.Utilities.Authentication +@model Grand.Web.Models.Customer.OidcFailedModel +@{ + Layout = "_SingleColumn"; + var key = Model.Mismatch + ? "Account.Oidc.Link.Mismatch" + : Model.IdentityTaken + ? "Account.Oidc.Failed.IdentityLinkedToOtherAccount" + : Model.SignedInAsOtherAccount + ? "Account.Oidc.Failed.SignedInAsOtherAccount" + : Model.SessionUnavailable + ? "Account.Oidc.Failed.SessionUnavailable" + : Model.Reason switch { + OidcLoginRefusal.AccountInactive => "Account.Oidc.Failed.AccountInactive", + OidcLoginRefusal.RegistrationDisabled => "Account.Oidc.Failed.RegistrationDisabled", + OidcLoginRefusal.LinkedToOtherIdentity => "Account.Oidc.Failed.LinkedToOtherIdentity", + OidcLoginRefusal.EmailNotVerified => "Account.Oidc.Failed.EmailNotVerified", + OidcLoginRefusal.ProviderChanged => "Account.Oidc.Failed.ProviderChanged", + _ => "Account.Oidc.Failed.Generic" + }; +} +
+

@Loc["Account.Oidc.Failed.Title"]

+
+
@Loc[key]
+
+
diff --git a/src/Web/Grand.Web/Views/OidcLogin/Link.cshtml b/src/Web/Grand.Web/Views/OidcLogin/Link.cshtml new file mode 100644 index 000000000..b9c87e78e --- /dev/null +++ b/src/Web/Grand.Web/Views/OidcLogin/Link.cshtml @@ -0,0 +1,11 @@ +@model Grand.Web.Models.Customer.OidcLinkModel +@{ + Layout = "_SingleColumn"; +} + diff --git a/src/Plugins/Authentication.OpenIdConnect/Views/Shared/Components/OidcLogin/Default.cshtml b/src/Web/Grand.Web/Views/Shared/Components/OidcLogin/Default.cshtml similarity index 71% rename from src/Plugins/Authentication.OpenIdConnect/Views/Shared/Components/OidcLogin/Default.cshtml rename to src/Web/Grand.Web/Views/Shared/Components/OidcLogin/Default.cshtml index e56b35025..389b4fb71 100644 --- a/src/Plugins/Authentication.OpenIdConnect/Views/Shared/Components/OidcLogin/Default.cshtml +++ b/src/Web/Grand.Web/Views/Shared/Components/OidcLogin/Default.cshtml @@ -4,6 +4,6 @@ From 12a0f9637677f4d49dac4c899fe7049a2085bffa Mon Sep 17 00:00:00 2001 From: support Date: Thu, 22 Oct 2026 22:59:45 +0200 Subject: [PATCH 4/8] Describe the built-in OpenID Connect sign-in --- docs/oidc-resource-server.md | 65 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/docs/oidc-resource-server.md b/docs/oidc-resource-server.md index 4a1ec1874..629105f25 100644 --- a/docs/oidc-resource-server.md +++ b/docs/oidc-resource-server.md @@ -16,8 +16,8 @@ identity provider and never issues tokens, registers clients or shows a consent a `WWW-Authenticate` header with `resource_metadata`. * Off by default (`OidcResourceServer:Enabled = false`): no scheme, no metadata endpoints, no behavior change. * One identity provider at a time. Not covered here: opaque tokens (see [Introspection](#8-introspection)) and - login to the admin panels. Browser sign-in of storefront users is a separate plugin - ([section 11](#11-browser-sign-in-openid-connect-login-plugin)). + login to the admin panels. Browser sign-in of storefront users is a separate, built-in + part ([section 11](#11-browser-sign-in-openid-connect)). Accepted signing algorithms: RS256/384/512, PS256/384/512, ES256/384/512. Tokens signed with HS\*, or with `alg: none`, are refused by the OpenID Connect scheme. @@ -137,7 +137,7 @@ customer in this order. authentication** (enabled for the customer and in the store) are **never** linked by e-mail, verified or not (403 without a link). A provider where someone can mark an address as verified without owning it (an administrator of another organization or realm creating a user) must not be enough to take over such an account. - They are connected once with the account's password: through the browser sign-in plugin (section 11), which asks + They are connected once with the account's password: through browser sign-in (section 11), which asks for the store password and two-factor code; their tokens then use that link. * Ordinary customers are linked by a verified e-mail. With `RequireEmailVerified = false` they are linked by an unverified one too: only for providers that never send `email_verified` and do not let users choose an address. @@ -180,8 +180,8 @@ A token alone grants no rights. To let a user call the API: The customer must be **linked** to the provider identity, and a link made by e-mail does not serve an account with admin panel access, a vendor or a staff store (section 3.1). Either: -* connect the account once with the browser sign-in plugin (section 11), which asks for its password; or -* without that plugin, let the token register the account (`AutoRegister = true`, section 3.2) and grant the access +* connect the account once with browser sign-in (section 11), which asks for its password; or +* without browser sign-in, let the token register the account (`AutoRegister = true`, section 3.2) and grant the access to that account: a link made by the registration is not a link made by e-mail. Granting back-office access to a customer linked by e-mail stops its tokens (403) until the account is connected with @@ -218,7 +218,7 @@ on unless every endpoint the resource covers scopes its data. panels, within the panel's scope). Deleting the OpenID Connect row removes the link and ends the customer's sessions started at the provider; the next provider sign-in connects the account again by the rules above. Use it when a person was deleted and created again at the provider ("already connected to another identity provider account"). The row is -listed even when only the resource server is used, without the sign-in plugin. Removing a link does not bring back +listed even when only the resource server is used, without browser sign-in. Removing a link does not bring back tokens refused by a back-channel logout: revocations are kept apart from the links. **Changing `Authority`.** The store records the provider the links were made with (`OidcLinkSettings`; trailing slash @@ -552,11 +552,11 @@ Ports are published on `127.0.0.1` only. Use the URLs above as `Authority` (`http://localhost:8080/realms/` for Keycloak, `http://localhost:8081` for Zitadel) with `RequireHttpsMetadata: false` in Development. -## 11. Browser sign-in (OpenID Connect login plugin) +## 11. Browser sign-in (OpenID Connect) -The plugin `Authentication.OpenIdConnect` (system name `ExternalAuth.OpenIdConnect`) lets customers and staff sign in +Browser sign-in (authentication method `ExternalAuth.OpenIdConnect`, built into GrandNode) lets customers and staff sign in to the storefront with the same provider that issues the API tokens. It is separate from the resource server: the -resource server validates access tokens, the plugin runs the browser flow (authorization code with PKCE) and gives the +resource server validates access tokens, browser sign-in runs the browser flow (authorization code with PKCE) and gives the visitor a normal GrandNode session. The provider proves who the user is; the customer's **groups and permissions in GrandNode** still decide what the user may do. @@ -564,7 +564,7 @@ GrandNode** still decide what the user may do. * A **sign-in button** next to the other external authentication methods. * The provider and its claim names are the ones of `OidcResourceServer` (`Authority`, `RequireHttpsMetadata`, - `Claims:*`). The plugin adds one client of its own (section 11.3). `RequireEmailVerified` applies to API tokens + `Claims:*`). Browser sign-in adds one client of its own (section 11.3). `RequireEmailVerified` applies to API tokens only; browser sign-in links an account automatically only when the provider reports the e-mail as verified, whatever that setting says. * The link between the provider's `sub` and the customer is stored in the same place as for API tokens (provider name @@ -612,13 +612,11 @@ Notes: ### 11.3 Configuration -1. Build the plugin and install it in the admin panel (*Configuration > Plugins*). The plugin output contains only its - own assembly and `Microsoft.AspNetCore.Authentication.OpenIdConnect.dll`; it uses the `Microsoft.IdentityModel.*` - assemblies of the application. -2. Enable it in *Configuration > External authentication*. The display order of the button is set on the plugin's - configuration page. -3. Configure the provider (section 11.4 or 11.5) and add the `OidcLogin` section. The secret goes into an environment - variable, never into the database or the admin panel. +1. Configure the provider (section 11.4 or 11.5) and add the `OidcLogin` section. The secret goes into an environment + variable, never into the database or the admin panel. Restart the application: the sign-in method exists only + while `OidcResourceServer:Authority` and `OidcLogin:ClientId` are set. +2. Enable it in *Configuration > External authentication*. The same page shows the provider and the client + (read-only, the secret only as set or not set). Section `OidcLogin` of `appsettings.json`: @@ -627,6 +625,7 @@ Section `OidcLogin` of `appsettings.json`: | `ClientId` | empty | Client id of the **confidential** client created for browser sign-in. | | `ClientSecret` | empty | Its secret. Prefer the environment variable `OidcLogin__ClientSecret`. | | `Scopes` | `openid profile email offline_access` | Space separated scopes requested at the provider. `openid` and `email` are needed. `offline_access` makes the provider issue a refresh token that outlives its ordinary session; every session needs that token (section 12.2). | +| `DisplayOrder` | `0` | Order of the button among the external authentication methods. | The section has more keys for back-office sessions, sign-out and the sign-in policy; they are described in [section 12](#12-sessions-sign-out-and-back-office-policy). @@ -644,11 +643,11 @@ The section has more keys for back-office sessions, sign-out and the sign-in pol ``` `Authority`, `RequireHttpsMetadata` and the claim names come from `OidcResourceServer`. `OidcResourceServer:Enabled` -does not have to be on for browser sign-in; the plugin only reads `Authority` and the other values above. It does not +does not have to be on for browser sign-in; browser sign-in only reads `Authority` and the other values above. It does not read `RequireEmailVerified`: automatic linking always needs an e-mail the provider reports as verified. -**Not configured.** When `Authority` or `ClientId` is empty the plugin registers no sign-in scheme and the button leads -to the failure page; it never causes an error page. +**Not configured.** When `Authority` or `ClientId` is empty no sign-in scheme and no authentication method are registered (the method +is not listed in *External authentication*), and `/oidc/login` leads to the failure page; it never causes an error page. Handler settings (fixed): authorization code flow with PKCE (S256), response mode `query`, `sub`, e-mail, `email_verified`, `given_name` and `family_name` are also read from the **user info endpoint**, provider tokens are not @@ -681,18 +680,18 @@ Use the realm of section 6. Create a **separate** client; do not reuse the publi Use the project of section 7. Create a **separate** application for the browser flow. 1. In the project add an application of type **Web** with authentication method **Code** (authorization code with a - client secret). PKCE is sent by the plugin. Copy the client id and the generated client secret + client secret). PKCE is sent by GrandNode. Copy the client id and the generated client secret (`OidcLogin__ClientSecret`; the secret is shown once). In the grant types of the application also tick **Refresh Token** (needed for every session, section 12.4). 2. Redirect URIs: `https:///signin-oidc` (an `http` redirect needs *Development Mode*). Post logout URIs are used only in `ProviderOnly` mode (section 13.7); otherwise logout is local. -3. The plugin reads the claims from the ID token or, when they are absent there, from the user info endpoint (the +3. GrandNode reads the claims from the ID token or, when they are absent there, from the user info endpoint (the handler merges both); Zitadel answers the user info endpoint for the scope `email`. To have the ID token carry the user information as well, enable the application's option to put user information into the ID token (token settings of the application). The default scopes `openid profile email offline_access` are sufficient; Zitadel issues a refresh token only for `offline_access`. 4. **The Actions v2 target of section 7 is not required for browser sign-in.** It runs on `preaccesstoken`, that is for - access tokens only, and the plugin does not use the access token. Verify this on your instance: after a test + access tokens only, and browser sign-in does not use the access token. Verify this on your instance: after a test sign-in with a verified e-mail the application log must not contain "OpenID Connect sign-in without a subject or an e-mail". If it does, enable the ID token option of step 3 and check that the user's e-mail is marked verified in Zitadel (an unverified e-mail is sent with `email_verified = false`). @@ -727,7 +726,7 @@ Use the project of section 7. Create a **separate** application for the browser | Symptom | Check | |---|---| -| The button is not shown | `OidcResourceServer:Authority` and `OidcLogin:ClientId` set? The plugin installed and enabled in *External authentication*? The application restarted after the install or a settings change? Without both settings, or before the restart, no sign-in scheme exists and the button is hidden. | +| The button is not shown | `OidcResourceServer:Authority` and `OidcLogin:ClientId` set? The method enabled in *External authentication*? The application restarted after a settings change? Without both settings, or before the restart, no sign-in scheme exists and the button is hidden. | | "Sign-in failed" after the provider page | The reason is in the application log (`OpenID Connect sign-in failed`, with the provider's error), never on the page. Common: wrong client secret, the user cancelled at the provider, the state/nonce cookie lost (a proxy, or a host name different from the one that started the flow). | | Provider error about the redirect URI | The redirect URI at the provider must equal `https:///signin-oidc` exactly: scheme, host, port, no trailing slash. Behind a TLS-terminating proxy GrandNode must see `https` (forwarded headers) or it builds an `http` URI. | | Failure caused by token lifetime ("not yet valid", "expired") | Clock skew between the application server and the provider; synchronize the clocks (NTP). | @@ -750,7 +749,7 @@ Back-Channel Logout 1.0). | The provider sends a back-channel logout (the user signs out at the provider, or an administrator ends the provider session) | The GrandNode sessions of that provider session (or of that user, when the logout names no session) end **at once**, for every kind of account. Access tokens of that user issued before the logout are refused too (section 12.2). | | The user signs out of GrandNode | The session ends at once. The provider session is not touched (section 12.7). | | The provider disables or deletes the user | **Every** session started by a provider sign-in, of a customer or of staff, ends at the next revalidation (`RevalidationMinutes`, section 12.2). Providers send no logout for a disabled or deleted user, so GrandNode notices at the next check. When the provider is unreachable, the session lasts until the last successful check is older than twice that interval, then ends. A refused revalidation also refuses the user's older access tokens. To end the sessions **at once**, sign the user out at the provider first (a back-channel logout), then disable the user. | -| The login plugin is uninstalled (and the application restarted), or `Authority` or `ClientId` is removed from the settings | Every provider session (customers too) ends at the next revalidation: nothing can confirm it any more. The user's access tokens stay valid: the provider refused nothing. Only *deactivating* the authentication method does not end sessions: it hides the button and turns `SsoOnly` off (passwords work again), and existing provider sessions go on being revalidated. | +| `Authority` or `ClientId` is removed from the settings (and the application restarted) | Every provider session (customers too) ends at the next revalidation: nothing can confirm it any more. The user's access tokens stay valid: the provider refused nothing. Only *deactivating* the authentication method does not end sessions: it hides the button and turns `SsoOnly` off (passwords work again), and existing provider sessions go on being revalidated. | | Idle time or total lifetime is exceeded | **Back-office sessions only** (`StaffIdleTimeoutMinutes`, `StaffMaxSessionHours`). Storefront customers are not limited by these settings. | After a registration through the provider or "Connect your account", the browser passes through the provider once more @@ -851,11 +850,7 @@ Zitadel issues a refresh token only when the client requests the scope `offline_ ``` Without either, **sign-in through Zitadel is refused for every account**: the visitor sees the failure page "not set up -completely" and the log has an error that names `offline_access`. The same happens with Keycloak when `offline_access` is not assigned to the client. The failure text is a -plugin resource that existing installations do not have yet: add the resource -`Plugins.ExternalAuth.OpenIdConnect.Failed.SessionUnavailable` in *Admin → Languages* (English text: "Signing in with the -identity provider is not set up completely. Use another sign-in method, or ask the administrator."). Do not -reinstall the plugin for it: uninstalling deletes its settings and the resources edited in the admin panel. +completely" and the log has an error that names `offline_access`. The same happens with Keycloak when `offline_access` is not assigned to the client. The failure text is the resource `Account.Oidc.Failed.SessionUnavailable` (*Admin → Languages*). If the ASP.NET Core Data Protection keys change (a new key ring, a different server without the shared ring), the stored refresh tokens cannot be read any more and all provider sessions end at the next revalidation; users sign in again. @@ -870,7 +865,7 @@ made by e-mail, section 3.1), customers included, signs in only through the prov sign-in of the Frontend API; * no password recovery e-mail is sent to it (a new password would be of no use), and a recovery link sent before reads as a wrong link; -* the policy applies only while the login plugin is installed, enabled and configured (`Authority` and `ClientId`); +* the policy applies only while browser sign-in is enabled and configured (`Authority` and `ClientId`); otherwise passwords work as before. An account that is **not** connected keeps its password: an account that has not signed in through the provider yet or @@ -880,7 +875,7 @@ back-office accounts first (section 11.2), then turn the setting on. ### 12.6 Panel login pages -The login pages of the Admin, Store and Vendor panels show the provider button when the login plugin is configured. +The login pages of the Admin, Store and Vendor panels show the provider button when browser sign-in is configured and enabled. After the provider sign-in the visitor returns to the panel they came from (`/admin`, `/store` or `/vendor`). The account rules of section 11.2 and the session limits of section 12.2 apply. @@ -902,7 +897,7 @@ rules of section 11.2 and the session limits of section 12.2 apply. |---|---| | Users are signed out every N minutes | The revalidation is refused. Check the client secret (`OidcLogin__ClientSecret`), that the user is still enabled at the provider, and that `offline_access` is in `OidcLogin:Scopes`. For back-office users also compare the interval with `StaffIdleTimeoutMinutes` and `StaffMaxSessionHours`. | | Sign-in shows "not set up completely" | No refresh token was issued: `offline_access` is missing from `OidcLogin:Scopes`, it is not assigned to the Keycloak client, or the Zitadel application lacks the Refresh Token grant (section 12.4); the error log names it. | -| Everyone is signed out after the plugin was uninstalled or `Authority`/`ClientId` removed | Expected (section 12.1): no one can confirm the sessions at the provider. Deactivating the authentication method alone does not sign anyone out. | +| Everyone is signed out after `Authority`/`ClientId` was removed | Expected (section 12.1): no one can confirm the sessions at the provider. Deactivating the authentication method alone does not sign anyone out. | | Every provider session ended during a provider outage | The provider was unreachable for longer than twice `RevalidationMinutes` since the last successful check. | | Back-channel logout has no effect | The URL must be reachable from the provider (its container or network), with the `https` URL of the store. Look for `Back-channel logout refused: ...` (warning) and the status the provider logs: 400 refused token, 503 metadata, 500 retry. For Keycloak check *Backchannel logout session required*. | | The provider reports repeated failures of the logout URL | 503 or 500 are retried by the provider; look for the error entry that precedes them. | @@ -1002,7 +997,7 @@ username follows the e-mail only when usernames are disabled in the store. ### 13.6 Misconfiguration -`ProviderOnly` without a working login (plugin not installed, not active for the store, or `Authority` or `ClientId` +`ProviderOnly` without a working login (not active for the store, or `Authority` or `ClientId` empty) never opens password sign-in. At startup, and again (at most once in five minutes) when a sign-in is refused for that reason, the log gets an error: @@ -1048,7 +1043,7 @@ step for that: sign in once in the browser first; the access token then uses tha | Symptom | Check | |---|---| -| Nobody can sign in, the log has the error of section 13.6 | The plugin is installed, enabled in *External authentication* for the store, and `Authority` and `ClientId` are set. Use a break-glass account meanwhile. | +| Nobody can sign in, the log has the error of section 13.6 | The method is enabled in *External authentication* for the store, and `Authority` and `ClientId` are set. Use a break-glass account meanwhile. | | A new user sees the registration form, or "New accounts cannot be registered" | `OidcLogin:AutoProvision` is `false` (section 13.4); set it to `true` to create accounts without the form. | | The Admin login page redirects and the password form does not show | Open `/admin/login?password=1` and sign in with an account listed in `BreakGlassAccounts` (the e-mail must match). | | Failure page about an unverified e-mail | The provider did not report `email_verified` as true; verify the e-mail at the provider (sections 11.4 and 11.5). | From 3204e24a3efe6beca9ee29381685ee25c294c787 Mon Sep 17 00:00:00 2001 From: support Date: Fri, 23 Oct 2026 06:59:46 +0200 Subject: [PATCH 5/8] Answer an unconfigured back-channel logout like a refused token and link the grid to the OpenID Connect card --- .../Services/OidcSsoSignInPolicy.cs | 2 +- .../Security/Oidc/OidcBackChannelLogoutEndpointTests.cs | 8 +++++++- .../Security/Oidc/OidcLoginProviderTests.cs | 6 ++++++ .../Admin/Views/ExternalAuthentication/Methods.cshtml | 2 ++ .../Security/Oidc/OidcBackChannelLogoutEndpoint.cs | 6 +++++- .../Grand.Web.Common/Security/Oidc/OidcLoginDefaults.cs | 2 +- 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Business/Grand.Business.Authentication/Services/OidcSsoSignInPolicy.cs b/src/Business/Grand.Business.Authentication/Services/OidcSsoSignInPolicy.cs index c911342a4..e4b87351e 100644 --- a/src/Business/Grand.Business.Authentication/Services/OidcSsoSignInPolicy.cs +++ b/src/Business/Grand.Business.Authentication/Services/OidcSsoSignInPolicy.cs @@ -11,7 +11,7 @@ namespace Grand.Business.Authentication.Services; /// /// OidcLogin:SsoOnly - an account connected to the identity provider with its password (a link not made by e-mail) -/// signs in only through the provider, while the OpenID Connect login is installed, active and configured; a user +/// signs in only through the provider, while the OpenID Connect login is configured and active; a user /// disabled at the provider then cannot use a GrandNode password either. Accounts without such a link keep the /// password: the break-glass account, and accounts still to be connected. /// OidcLogin:SignInMode = ProviderOnly - every account signs in through the provider; the password stays only for diff --git a/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs index 683dff265..03d58c67f 100644 --- a/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs @@ -192,7 +192,13 @@ public async Task UnreadableBody_400() public async Task NotConfigured_400() { _schemeRegistered = false; - Assert.AreEqual(400, (await Post(Token())).Response.StatusCode); + var context = await Post(Token()); + Assert.AreEqual(400, context.Response.StatusCode); + //the answer of a refused token: an outsider learns nothing about whether the sign-in is set up + context.Response.Body.Position = 0; + var body = await new StreamReader(context.Response.Body).ReadToEndAsync(); + StringAssert.Contains(body, "The logout token was refused"); + Assert.IsFalse(body.Contains("configured", StringComparison.OrdinalIgnoreCase), body); } [TestMethod] diff --git a/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginProviderTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginProviderTests.cs index 165c947a9..b272d6878 100644 --- a/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginProviderTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcLoginProviderTests.cs @@ -30,6 +30,12 @@ public async Task PanelSignInPath_NoScheme_Null() public void SystemName_IsTheLinkName() => Assert.AreEqual(OidcResourceServerDefaults.ProviderSystemName, new OidcLoginProvider(new OidcLoginConfig(), new Mock().Object).SystemName); + //the grid's configure link opens the read-only card below the grid, not the same page again + [TestMethod] + public void ConfigurationUrl_PointsAtTheCard() => + Assert.AreEqual("../ExternalAuthentication/Methods#oidc-sign-in", + new OidcLoginProvider(new OidcLoginConfig(), new Mock().Object).ConfigurationUrl); + [TestMethod] public void Priority_FromSettings() => Assert.AreEqual(7, new OidcLoginProvider(new OidcLoginConfig { DisplayOrder = 7 }, new Mock().Object).Priority); diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml index 9af822f46..6f9c90b93 100644 --- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml +++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml @@ -41,6 +41,8 @@ @* the identity provider and the client come from appsettings and are shown read-only; the secret is never shown *@ @if (Model != null) { + @* target of the grid's configure link of the OpenID Connect row (OidcLoginDefaults.ConfigurationUrl) *@ +
@Html.Raw(Loc["Admin.Plugins.ExternalAuthenticationMethods.Oidc.Description"]) diff --git a/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs index 7e18c6d60..d706ddc4c 100644 --- a/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs @@ -37,9 +37,13 @@ public static async Task Handle(HttpContext context) if (string.IsNullOrEmpty(token)) return Error("The logout_token parameter is missing"); + //mapped on every installation: the caller gets the answer of a refused token, only the log says why if (await services.GetRequiredService() .GetSchemeAsync(OidcLoginDefaults.AuthenticationScheme) == null) - return Error("OpenID Connect sign-in is not configured"); + { + logger.LogWarning("Back-channel logout refused: OpenID Connect sign-in is not configured"); + return Error("The logout token was refused"); + } var options = services.GetRequiredService>() .Get(OidcLoginDefaults.AuthenticationScheme); diff --git a/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginDefaults.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginDefaults.cs index b6199c3cb..0976a5c35 100644 --- a/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginDefaults.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcLoginDefaults.cs @@ -12,6 +12,6 @@ public static class OidcLoginDefaults public const string BackChannelLogoutPath = "oidc/backchannel-logout"; public const string LoginPath = "/oidc/login"; public const string FailedPath = "/oidc/failed"; - public const string ConfigurationUrl = "../ExternalAuthentication/Methods"; + public const string ConfigurationUrl = "../ExternalAuthentication/Methods#oidc-sign-in"; public static readonly TimeSpan PendingLifetime = TimeSpan.FromMinutes(15); } From 890b86e299d3ee1719a7c1f0ddae3450b74a7690 Mon Sep 17 00:00:00 2001 From: support Date: Fri, 23 Oct 2026 06:59:57 +0200 Subject: [PATCH 6/8] Describe the back-channel answer of a store without OpenID Connect sign-in --- docs/oidc-resource-server.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/oidc-resource-server.md b/docs/oidc-resource-server.md index 629105f25..4c3152021 100644 --- a/docs/oidc-resource-server.md +++ b/docs/oidc-resource-server.md @@ -814,7 +814,7 @@ Answers (always `Cache-Control: no-store`): | Status | Meaning | |---|---| | 200 | Sessions ended (also when there was nothing to end). | -| 400 | JSON `{"error":"invalid_request", ...}`: no or invalid `logout_token`, the form could not be read, or browser sign-in is not configured. | +| 400 | JSON `{"error":"invalid_request", ...}`: no or invalid `logout_token`, the form could not be read, or browser sign-in is not configured (answered like a refused token, `The logout token was refused`; only the log names the reason). | | 503 | The provider's metadata could not be obtained; the provider may retry. | | 500 | Ending the sessions failed; the provider may retry, and the same logout token is accepted again. | From d55015ffec0de459ba61b33abcdbcc1004e2ec4a Mon Sep 17 00:00:00 2001 From: support Date: Fri, 23 Oct 2026 08:20:28 +0200 Subject: [PATCH 7/8] Show the OpenID Connect sign-in card whenever the sign-in is configured and check the scheme before reading a back-channel logout --- .../ExternalAuthenticationControllerTests.cs | 48 ++++++++++++++++--- .../OidcBackChannelLogoutEndpointTests.cs | 29 +++++++++++ .../ExternalAuthentication/Methods.cshtml | 4 +- .../ExternalAuthenticationController.cs | 30 ++++++++---- .../ExternalAuthentication/OidcLinksModel.cs | 6 +++ .../Oidc/OidcBackChannelLogoutEndpoint.cs | 17 +++---- 6 files changed, 107 insertions(+), 27 deletions(-) diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/ExternalAuthenticationControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/ExternalAuthenticationControllerTests.cs index 24e1e96ee..0dc5a9665 100644 --- a/src/Tests/Grand.Web.Admin.Tests/Controllers/ExternalAuthenticationControllerTests.cs +++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/ExternalAuthenticationControllerTests.cs @@ -15,17 +15,18 @@ public class ExternalAuthenticationControllerTests { private const string Authority = "https://idp.test"; - private static async Task Methods(bool resourceServerEnabled, string clientSecret) + private readonly Mock _linkService = new(); + + private async Task Methods(bool resourceServerEnabled, string clientSecret, string clientId = "shop") { - var linkService = new Mock(); - linkService.Setup(x => x.GetState()).ReturnsAsync(new OidcLinkState(Authority, Authority, 3)); + _linkService.Setup(x => x.GetState()).ReturnsAsync(new OidcLinkState(Authority, Authority, 3)); var controller = new ExternalAuthenticationController(new Mock().Object, new ExternalAuthenticationSettings(), new Mock().Object, new Mock().Object); return await controller.Methods( new OidcResourceServerConfig { Enabled = resourceServerEnabled, Authority = Authority }, - new OidcLoginConfig { ClientId = "shop", ClientSecret = clientSecret }, - linkService.Object); + new OidcLoginConfig { ClientId = clientId, ClientSecret = clientSecret }, + _linkService.Object); } [TestMethod] @@ -50,8 +51,41 @@ public async Task Methods_SecretEmpty_ReportsNoSecret() } [TestMethod] - public async Task Methods_ResourceServerDisabled_ReturnsViewWithoutModel() + public async Task Methods_Configured_ShowsBothCards() + { + var model = (OidcLinksModel)((ViewResult)await Methods(true, "s3cr3t")).Model!; + + Assert.IsTrue(model.SignInConfigured); + Assert.IsTrue(model.LinksConfigured); + Assert.AreEqual(3, model.LinkCount); + } + + //browser sign-in needs only Authority and ClientId: the grid lists it and its configure link needs the card + [TestMethod] + public async Task Methods_ResourceServerDisabled_ShowsSignInCardOnly() + { + var model = (OidcLinksModel)((ViewResult)await Methods(false, "s3cr3t")).Model!; + + Assert.IsTrue(model.SignInConfigured); + Assert.IsFalse(model.LinksConfigured); + Assert.AreEqual(Authority, model.ConfiguredAuthority); + Assert.AreEqual("shop", model.ClientId); + _linkService.Verify(x => x.GetState(), Times.Never); + } + + //the resource server alone: the links card, no sign-in card with an empty client + [TestMethod] + public async Task Methods_ClientIdEmpty_ShowsLinksCardOnly() + { + var model = (OidcLinksModel)((ViewResult)await Methods(true, "", clientId: "")).Model!; + + Assert.IsFalse(model.SignInConfigured); + Assert.IsTrue(model.LinksConfigured); + } + + [TestMethod] + public async Task Methods_NothingConfigured_ReturnsViewWithoutModel() { - Assert.IsNull(((ViewResult)await Methods(false, "s3cr3t")).Model); + Assert.IsNull(((ViewResult)await Methods(false, "", clientId: "")).Model); } } diff --git a/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs index 03d58c67f..098878f34 100644 --- a/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs +++ b/src/Tests/Grand.Web.Common.Tests/Security/Oidc/OidcBackChannelLogoutEndpointTests.cs @@ -201,6 +201,35 @@ public async Task NotConfigured_400() Assert.IsFalse(body.Contains("configured", StringComparison.OrdinalIgnoreCase), body); } + //without the sign-in nothing of the request is read: the body stays unconsumed and the answer is the same + [TestMethod] + public async Task NotConfigured_BodyNotRead() + { + _schemeRegistered = false; + var context = new DefaultHttpContext { RequestServices = Services() }; + context.Request.Method = "POST"; + context.Request.ContentType = "application/x-www-form-urlencoded"; + context.Request.Body = new UnreadableStream(); + context.Response.Body = new MemoryStream(); + + var result = await OidcBackChannelLogoutEndpoint.Handle(context); + await result.ExecuteAsync(context); + + Assert.AreEqual(400, context.Response.StatusCode); + } + + private sealed class UnreadableStream : MemoryStream + { + public override int Read(byte[] buffer, int offset, int count) => + throw new InvalidOperationException("the form was read"); + + public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) => + throw new InvalidOperationException("the form was read"); + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => + throw new InvalidOperationException("the form was read"); + } + [TestMethod] public async Task MetadataUnobtainable_503() { diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml index 6f9c90b93..18908801e 100644 --- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml +++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/ExternalAuthentication/Methods.cshtml @@ -39,7 +39,7 @@ @* the identity provider and the client come from appsettings and are shown read-only; the secret is never shown *@ - @if (Model != null) + @if (Model?.SignInConfigured == true) { @* target of the grid's configure link of the OpenID Connect row (OidcLoginDefaults.ConfigurationUrl) *@ @@ -66,7 +66,7 @@ } @* the OpenID Connect account links belong to one identity provider: a subject is unique only there *@ - @if (Model != null) + @if (Model?.LinksConfigured == true) { @if (Model.ProviderUnknown) diff --git a/src/Web/Grand.Web.Admin/Controllers/ExternalAuthenticationController.cs b/src/Web/Grand.Web.Admin/Controllers/ExternalAuthenticationController.cs index 59f506f4b..1504452b7 100644 --- a/src/Web/Grand.Web.Admin/Controllers/ExternalAuthenticationController.cs +++ b/src/Web/Grand.Web.Admin/Controllers/ExternalAuthenticationController.cs @@ -46,20 +46,30 @@ public ExternalAuthenticationController(IExternalAuthenticationService openAuthe public async Task Methods([FromServices] OidcResourceServerConfig resourceServerConfig, [FromServices] OidcLoginConfig loginConfig, [FromServices] IOidcLinkService linkService) { - //the OpenID Connect sign-in and its account links, only while the provider is configured - if (!ResourceServerConfigured(resourceServerConfig)) + //the sign-in card follows the sign-in method (Authority and ClientId), the links card the resource server + var signInConfigured = loginConfig.IsConfigured(resourceServerConfig); + var linksConfigured = ResourceServerConfigured(resourceServerConfig); + if (!signInConfigured && !linksConfigured) return View(); - var state = await linkService.GetState(); - return View(new OidcLinksModel { - ConfiguredAuthority = state.ConfiguredAuthority, - LinkedAuthority = state.LinkedAuthority, - LinkCount = state.LinkCount, - ProviderChanged = state.ProviderChanged, - ProviderUnknown = state.ProviderUnknown, + var model = new OidcLinksModel { + SignInConfigured = signInConfigured, + LinksConfigured = linksConfigured, + ConfiguredAuthority = resourceServerConfig.Authority, ClientId = loginConfig.ClientId, ClientSecretSet = !string.IsNullOrWhiteSpace(loginConfig.ClientSecret) - }); + }; + if (linksConfigured) + { + var state = await linkService.GetState(); + model.ConfiguredAuthority = state.ConfiguredAuthority; + model.LinkedAuthority = state.LinkedAuthority; + model.LinkCount = state.LinkCount; + model.ProviderChanged = state.ProviderChanged; + model.ProviderUnknown = state.ProviderUnknown; + } + + return View(model); } /// Another identity provider: every OpenID Connect link is removed, people connect again at their next sign-in diff --git a/src/Web/Grand.Web.AdminShared/Models/ExternalAuthentication/OidcLinksModel.cs b/src/Web/Grand.Web.AdminShared/Models/ExternalAuthentication/OidcLinksModel.cs index 8ab8a132f..33ff0b145 100644 --- a/src/Web/Grand.Web.AdminShared/Models/ExternalAuthentication/OidcLinksModel.cs +++ b/src/Web/Grand.Web.AdminShared/Models/ExternalAuthentication/OidcLinksModel.cs @@ -9,6 +9,12 @@ public class OidcLinksModel public bool ProviderChanged { get; set; } public bool ProviderUnknown { get; set; } + /// Browser sign-in configured (OidcResourceServer:Authority and OidcLogin:ClientId): the sign-in card + public bool SignInConfigured { get; set; } + + /// Resource server enabled: the account links card + public bool LinksConfigured { get; set; } + /// OidcLogin:ClientId of the browser sign-in public string ClientId { get; set; } diff --git a/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs index d706ddc4c..85ee40e30 100644 --- a/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs @@ -22,6 +22,15 @@ public static async Task Handle(HttpContext context) var services = context.RequestServices; var logger = services.GetRequiredService().CreateLogger(typeof(OidcBackChannelLogoutEndpoint)); + //mapped on every installation: without the sign-in nothing of the request is read, and the caller gets the + //answer of a refused token; only the log says why + if (await services.GetRequiredService() + .GetSchemeAsync(OidcLoginDefaults.AuthenticationScheme) == null) + { + logger.LogWarning("Back-channel logout refused: OpenID Connect sign-in is not configured"); + return Error("The logout token was refused"); + } + if (!context.Request.HasFormContentType) return Error("The request must be a form post"); IFormCollection form; @@ -37,14 +46,6 @@ public static async Task Handle(HttpContext context) if (string.IsNullOrEmpty(token)) return Error("The logout_token parameter is missing"); - //mapped on every installation: the caller gets the answer of a refused token, only the log says why - if (await services.GetRequiredService() - .GetSchemeAsync(OidcLoginDefaults.AuthenticationScheme) == null) - { - logger.LogWarning("Back-channel logout refused: OpenID Connect sign-in is not configured"); - return Error("The logout token was refused"); - } - var options = services.GetRequiredService>() .Get(OidcLoginDefaults.AuthenticationScheme); var configuration = await Configuration(options, context, logger); From 216d0e768783d2149954c154d462bb4442de2ba5 Mon Sep 17 00:00:00 2001 From: support Date: Fri, 23 Oct 2026 11:39:04 +0200 Subject: [PATCH 8/8] Log a back-channel logout of a store without OpenID Connect sign-in at debug level --- .../Security/Oidc/OidcBackChannelLogoutEndpoint.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs b/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs index 85ee40e30..2ce330c5a 100644 --- a/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs +++ b/src/Web/Grand.Web.Common/Security/Oidc/OidcBackChannelLogoutEndpoint.cs @@ -23,11 +23,11 @@ public static async Task Handle(HttpContext context) var logger = services.GetRequiredService().CreateLogger(typeof(OidcBackChannelLogoutEndpoint)); //mapped on every installation: without the sign-in nothing of the request is read, and the caller gets the - //answer of a refused token; only the log says why + //answer of a refused token; only the log says why, at debug level: anyone can post here if (await services.GetRequiredService() .GetSchemeAsync(OidcLoginDefaults.AuthenticationScheme) == null) { - logger.LogWarning("Back-channel logout refused: OpenID Connect sign-in is not configured"); + logger.LogDebug("Back-channel logout refused: OpenID Connect sign-in is not configured"); return Error("The logout token was refused"); }