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;
|
=> defaultCookieName + ReceiverSuffix + key;
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
/// <param name="key">The unique envelope receiver key.</param>
|
/// <param name="cookieName">The full cookie name in the format <c>{defaultCookieName}SignFLOWReceiver.{key}</c>.</param>
|
||||||
/// <returns>A cookie name in the format <c>{defaultCookieName}SignFLOWReceiver.{key}</c>.</returns>
|
/// <param name="defaultCookieName">The base cookie name configured in <c>AuthApiParams</c>.</param>
|
||||||
public static string GetEnvelopeReceiverCookieName(string key)
|
/// <returns>The envelope receiver key, or <see langword="null"/> if the cookie name does not match the expected format.</returns>
|
||||||
=> "AuthToken" + ReceiverSuffix + key;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@
|
|||||||
<RepositoryUrl>https://git.dd/AppStd/DigitalData.Auth</RepositoryUrl>
|
<RepositoryUrl>https://git.dd/AppStd/DigitalData.Auth</RepositoryUrl>
|
||||||
<PackageTags>digital data auth claims jwt constants</PackageTags>
|
<PackageTags>digital data auth claims jwt constants</PackageTags>
|
||||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||||
<Version>1.0.0</Version>
|
<Version>1.0.1</Version>
|
||||||
<AssemblyVersion>1.0.0</AssemblyVersion>
|
<AssemblyVersion>1.0.1</AssemblyVersion>
|
||||||
<FileVersion>1.0.0</FileVersion>
|
<FileVersion>1.0.1</FileVersion>
|
||||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user