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.
This commit is contained in:
@@ -17,11 +17,30 @@ namespace DigitalData.Auth.Claims
|
||||
=> defaultCookieName + ReceiverSuffix + key;
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see langword="null"/> if the cookie name does not match the expected format.
|
||||
/// </summary>
|
||||
/// <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 key)
|
||||
=> "AuthToken" + ReceiverSuffix + key;
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user