Files
DigitalData.Auth/DigitalData.Auth.Claims/CookieNames.cs
TekH 2551de233f Refactor cookie handling and bump version to 1.0.1
Refactored `CookieNames.cs` to replace the `GetEnvelopeReceiverCookieName(string key)` method with new methods for extracting envelope receiver keys from cookie names:
- Added `GetEnvelopeReceiverKeyOrDefault` to extract keys or return `null` if the format is invalid.
- Added `TryGetEnvelopeReceiverKey` to attempt key extraction with a success flag.

Updated `DigitalData.Auth.Claims.csproj` to increment `Version`, `AssemblyVersion`, and `FileVersion` from 1.0.0 to 1.0.1, reflecting the new functionality.
2026-05-29 09:50:10 +02:00

47 lines
2.6 KiB
C#

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