From 310d480f599c7a4f5694fa458b560877b3547769 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 14 Jan 2025 20:43:41 +0100 Subject: [PATCH] feat(CookieOptionsProvider): Erstellen zur Bereitstellung von Cookie-Optionen mit Basis-Cookie-Option und dynamischer Ablaufzeit --- .../Config/CookieOptionsProvider.cs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/DigitalData.Auth.API/Config/CookieOptionsProvider.cs diff --git a/src/DigitalData.Auth.API/Config/CookieOptionsProvider.cs b/src/DigitalData.Auth.API/Config/CookieOptionsProvider.cs new file mode 100644 index 0000000..1b6ab56 --- /dev/null +++ b/src/DigitalData.Auth.API/Config/CookieOptionsProvider.cs @@ -0,0 +1,73 @@ +namespace DigitalData.Auth.API.Config +{ + public class CookieOptionsProvider + { + public TimeSpan Lifetime { get; init; } = new(1, 0, 0); + + private readonly CookieOptions _optionsBase = new(); + + #region CookieOptions + // + // Summary: + // Gets or sets the domain to associate the cookie with. + // + // Returns: + // The domain to associate the cookie with. + public string? Domain { get => _optionsBase.Domain; set => _optionsBase.Domain = value; } + + // + // Summary: + // Gets or sets the cookie path. + // + // Returns: + // The cookie path. + public string? Path { get => _optionsBase.Path; set => _optionsBase.Path = value; } + // + // Summary: + // Gets or sets the expiration date and time for the cookie. + // + // Returns: + // The expiration date and time for the cookie. + public DateTimeOffset? Expires { get => _optionsBase.Expires; set => _optionsBase.Expires = value; } + // + // Summary: + // Gets or sets a value that indicates whether to transmit the cookie using Secure + // Sockets Layer (SSL)--that is, over HTTPS only. + // + // Returns: + // true to transmit the cookie only over an SSL connection (HTTPS); otherwise, false. + public bool Secure { get => _optionsBase.Secure; set => _optionsBase.Secure = value; } + // + // Summary: + // Gets or sets the value for the SameSite attribute of the cookie. The default + // value is Microsoft.AspNetCore.Http.SameSiteMode.Unspecified + // + // Returns: + // The Microsoft.AspNetCore.Http.SameSiteMode representing the enforcement mode + // of the cookie. + public SameSiteMode SameSite { get => _optionsBase.SameSite; set => _optionsBase.SameSite = value; } + // + // Summary: + // Gets or sets a value that indicates whether a cookie is inaccessible by client-side + // script. + // + // Returns: + // true if a cookie must not be accessible by client-side script; otherwise, false. + public bool HttpOnly { get => _optionsBase.HttpOnly; set => _optionsBase.HttpOnly = value; } + // + // Summary: + // Gets or sets the max-age for the cookie. + // + // Returns: + // The max-age date and time for the cookie. + public TimeSpan? MaxAge { get => _optionsBase.MaxAge; set => _optionsBase.MaxAge = value; } + // + // Summary: + // Indicates if this cookie is essential for the application to function correctly. + // If true then consent policy checks may be bypassed. The default value is false. + public bool IsEssential { get => _optionsBase.IsEssential; set => _optionsBase.IsEssential = value; } + #endregion + + public CookieOptions Create(TimeSpan? lifetime = null) => new(_optionsBase) { Expires = DateTime.UtcNow.AddTicks(lifetime?.Ticks ?? Lifetime.Ticks) }; + } +} \ No newline at end of file