diff --git a/DigitalData.Auth.Claims/CookieNames.cs b/DigitalData.Auth.Claims/CookieNames.cs index 8efcdce..140440f 100644 --- a/DigitalData.Auth.Claims/CookieNames.cs +++ b/DigitalData.Auth.Claims/CookieNames.cs @@ -17,11 +17,30 @@ namespace DigitalData.Auth.Claims => defaultCookieName + ReceiverSuffix + key; /// - /// Builds the cookie name for an envelope receiver token. This overload assumes a default cookie name of "AuthToken". + /// Extracts the envelope receiver key from a cookie name, or returns if the cookie name does not match the expected format. /// - /// The unique envelope receiver key. - /// A cookie name in the format {defaultCookieName}SignFLOWReceiver.{key}. - public static string GetEnvelopeReceiverCookieName(string key) - => "AuthToken" + ReceiverSuffix + key; + /// 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; + } } } diff --git a/DigitalData.Auth.Claims/DigitalData.Auth.Claims.csproj b/DigitalData.Auth.Claims/DigitalData.Auth.Claims.csproj index 327398d..0363609 100644 --- a/DigitalData.Auth.Claims/DigitalData.Auth.Claims.csproj +++ b/DigitalData.Auth.Claims/DigitalData.Auth.Claims.csproj @@ -19,9 +19,9 @@ https://git.dd/AppStd/DigitalData.Auth digital data auth claims jwt constants false - 1.0.0 - 1.0.0 - 1.0.0 + 1.0.1 + 1.0.1 + 1.0.1 false