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) }; } }