From dc7ea2dae6b83054ba3b147e7d5464a1c942dd6a Mon Sep 17 00:00:00 2001 From: Dav-id Date: Tue, 24 Oct 2023 09:49:37 +0000 Subject: [PATCH] feat: allow configuring cookie domain --- src/Logto.AspNetCore.Authentication/LogtoOptions.cs | 4 ++++ .../extensions/AuthenticationBuilderExtensions.cs | 1 + 2 files changed, 5 insertions(+) diff --git a/src/Logto.AspNetCore.Authentication/LogtoOptions.cs b/src/Logto.AspNetCore.Authentication/LogtoOptions.cs index 079b770..3d67a30 100644 --- a/src/Logto.AspNetCore.Authentication/LogtoOptions.cs +++ b/src/Logto.AspNetCore.Authentication/LogtoOptions.cs @@ -63,6 +63,10 @@ public class LogtoOptions /// set this value to `true` since they are not included in the ID token. /// public bool GetClaimsFromUserInfoEndpoint { get; set; } = false; + /// + /// The domain to associate the cookie with. Allows multiple applications to share the cookie such as on sub-domains. + /// + public string? CookieDomain { get; set; } = null; } /// diff --git a/src/Logto.AspNetCore.Authentication/extensions/AuthenticationBuilderExtensions.cs b/src/Logto.AspNetCore.Authentication/extensions/AuthenticationBuilderExtensions.cs index b646691..4d4485f 100644 --- a/src/Logto.AspNetCore.Authentication/extensions/AuthenticationBuilderExtensions.cs +++ b/src/Logto.AspNetCore.Authentication/extensions/AuthenticationBuilderExtensions.cs @@ -73,6 +73,7 @@ private static void ConfigureCookieOptions(string authenticationScheme, CookieAu { options.Cookie.Name = $"Logto.Cookie.{logtoOptions.AppId}"; options.SlidingExpiration = true; + options.Cookie.Domain = logtoOptions.CookieDomain; options.Events = new CookieAuthenticationEvents { OnValidatePrincipal = context => new LogtoCookieContextManager(authenticationScheme, context).Handle()