namespace DigitalData.Auth.Claims { /// /// Provides helpers for building cookie names used in the DigitalData.Auth ecosystem. /// public static class CookieNames { private const string ReceiverSuffix = "SignFLOWReceiver."; /// /// Builds the cookie name for an envelope receiver token. /// /// The base cookie name configured in AuthApiParams. /// The unique envelope receiver key. /// A cookie name in the format {defaultCookieName}SignFLOWReceiver.{key}. public static string GetEnvelopeReceiverCookieName(string defaultCookieName, string key) => defaultCookieName + ReceiverSuffix + key; /// /// Extracts the envelope receiver key from a cookie name, or returns if the cookie name does not match the expected format. /// /// The full cookie name in the format {defaultCookieName}SignFLOWReceiver.{key}. /// The base cookie name configured in AuthApiParams. /// The envelope receiver key, or if the cookie name does not match the expected format. public static string? GetEnvelopeReceiverKeyOrDefault(string cookieName, string defaultCookieName) { var prefix = defaultCookieName + ReceiverSuffix; return cookieName.StartsWith(prefix, StringComparison.Ordinal) ? cookieName[prefix.Length..] : null; } /// /// Tries to extract the envelope receiver key from a cookie name. /// /// The full cookie name in the format {defaultCookieName}SignFLOWReceiver.{key}. /// The base cookie name configured in AuthApiParams. /// The extracted envelope receiver key if the cookie name matches the expected format; otherwise . /// if the key was successfully extracted; otherwise . public static bool TryGetEnvelopeReceiverKey(string cookieName, string defaultCookieName, out string? key) { key = GetEnvelopeReceiverKeyOrDefault(cookieName, defaultCookieName); return key is not null; } } }