Compare commits

...

7 Commits

Author SHA1 Message Date
bdf68b6bc4 Bump version to 1.0.2
Updated project version from 1.0.1 to 1.0.2 in the `.csproj` file.
This includes changes to `<Version>`, `<AssemblyVersion>`, and
`<FileVersion>` to reflect a minor update or patch.
2026-05-29 10:24:12 +02:00
c69635fc43 Refactor and enhance CookieNamesTests methods
Refactored and renamed several test methods in `CookieNamesTests` to improve clarity and align with updated functionality. Replaced methods testing `GetEnvelopeReceiverKeyOrDefault` with new methods for `GetEnvelopeReceiverCookieName` and `GetEnvelopeKeyOrDefault`. Added new tests to validate behavior with default cookie names and incorrect bases. Renamed `TryGetEnvelopeReceiverKey` methods to `TryGetEnvelopeKey` for consistency, while maintaining their functionality.
2026-05-29 10:21:50 +02:00
98fbbea5c3 Refactor cookie name methods and update tests
Renamed and refactored methods in `CookieNames` to improve naming consistency and simplify usage. Added overloads with default `defaultCookieName` set to `"AuthToken"`. Updated XML documentation to reflect these changes.

Updated `CookieNamesTests` to use the new method names and signatures. Adjusted test cases to align with the new default behavior and ensure compatibility.

These changes enhance code readability, reduce redundancy, and standardize method naming conventions.
2026-05-29 10:21:27 +02:00
f455241af1 Add unit tests for CookieNames class functionality
Added a new `CookieNamesTests` class to validate methods in the
`CookieNames` class, including scenarios for generating and
extracting cookie names and keys. Tests cover valid, invalid,
and unrelated cookie names, as well as round-trip validation
of `GetEnvelopeReceiverCookieName` and `GetEnvelopeReceiverKeyOrDefault`.

Updated `DigitalData.Auth.Tests.csproj` to include a project
reference to `DigitalData.Auth.Claims` for testing purposes.
2026-05-29 09:50:24 +02:00
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
25387238e3 Bump version to 1.4.1 in project file
Updated `DigitalData.Auth.API.csproj` to increment `<Version>`, `<AssemblyVersion>`, and `<FileVersion>` from `1.4.0` to `1.4.1`. This minor version update reflects bug fixes or small improvements without introducing breaking changes.
2026-05-29 09:12:47 +02:00
2c78ed106c Add CookieNames helper for constructing cookie names
Introduce a new static class `CookieNames` in the `DigitalData.Auth.Claims` namespace to centralize and standardize the construction of cookie names for envelope receiver tokens.

- Added `GetEnvelopeReceiverCookieName` methods to generate cookie names with or without a default cookie name.
- Updated `AuthController` to use the `CookieNames` helper for constructing cookie names, replacing direct concatenation logic.
- Improved maintainability and consistency of cookie naming conventions across the application.
2026-05-29 09:01:21 +02:00
6 changed files with 255 additions and 7 deletions

View File

@@ -0,0 +1,66 @@
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>
/// Builds the cookie name for an envelope receiver token.
/// </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;
/// <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? GetEnvelopeKeyOrDefault(string cookieName, string defaultCookieName = "AuthToken")
{
var prefix = defaultCookieName + ReceiverSuffix;
return cookieName.StartsWith(prefix, StringComparison.Ordinal)
? cookieName[prefix.Length..]
: null;
}
/// <summary>
/// Tries to extract the envelope 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 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 TryGetEnvelopeKey(string cookieName, string defaultCookieName, out string? key)
{
key = GetEnvelopeKeyOrDefault(cookieName, defaultCookieName);
return key is not null;
}
/// <summary>
/// Tries to extract the envelope key from a cookie name.
/// </summary>
/// <param name="cookieName">The full cookie name in the format <c>{defaultCookieName}SignFLOWReceiver.{key}</c>.</param>
/// <param name="key">The extracted envelope 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 TryGetEnvelopeKey(string cookieName, out string? key)
{
key = GetEnvelopeKeyOrDefault(cookieName, "AuthToken");
return key is not null;
}
}
}

View File

@@ -19,9 +19,9 @@
<RepositoryUrl>https://git.dd/AppStd/DigitalData.Auth</RepositoryUrl>
<PackageTags>digital data auth claims jwt constants</PackageTags>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Version>1.0.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>1.0.0</FileVersion>
<Version>1.0.2</Version>
<AssemblyVersion>1.0.2</AssemblyVersion>
<FileVersion>1.0.2</FileVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>

View File

@@ -0,0 +1,180 @@
using DigitalData.Auth.Claims;
namespace DigitalData.Auth.Tests.Claims;
[TestFixture]
public class CookieNamesTests
{
private const string DefaultCookieName = "AuthToken";
private const string Key = "NTE3YmI5YzUtNjA4Mi00ZTYxLWFhYTUtOTg0NjM4";
[Test]
public void GetEnvelopeReceiverCookieName_ShouldReturnCorrectFormat()
{
// Arrange
var expected = $"{DefaultCookieName}SignFLOWReceiver.{Key}";
// Act
var result = CookieNames.GetEnvelopeReceiverCookieName(DefaultCookieName, Key);
// Assert
Assert.That(result, Is.EqualTo(expected));
}
[Test]
public void GetEnvelopeReceiverCookieName_WithKeyOnly_ShouldUseDefaultCookieName()
{
// Arrange
var expected = $"{DefaultCookieName}SignFLOWReceiver.{Key}";
// Act
var result = CookieNames.GetEnvelopeReceiverCookieName(Key);
// Assert
Assert.That(result, Is.EqualTo(expected));
}
[Test]
public void GetEnvelopeKeyOrDefault_ShouldReturnKey_WhenCookieNameIsValid()
{
// Arrange
var cookieName = CookieNames.GetEnvelopeReceiverCookieName(DefaultCookieName, Key);
// Act
var result = CookieNames.GetEnvelopeKeyOrDefault(cookieName, DefaultCookieName);
// Assert
Assert.That(result, Is.EqualTo(Key));
}
[Test]
public void GetEnvelopeKeyOrDefault_WithDefaultParam_ShouldReturnKey_WhenCookieUsesDefaultBase()
{
// Arrange
var cookieName = CookieNames.GetEnvelopeReceiverCookieName(Key); // uses "AuthToken" base
// Act
var result = CookieNames.GetEnvelopeKeyOrDefault(cookieName); // defaultCookieName = "AuthToken"
// Assert
Assert.That(result, Is.EqualTo(Key));
}
[Test]
public void GetEnvelopeKeyOrDefault_ShouldReturnNull_WhenCookieNameHasWrongBase()
{
// Arrange
var cookieName = CookieNames.GetEnvelopeReceiverCookieName("OtherCookie", Key);
// Act
var result = CookieNames.GetEnvelopeKeyOrDefault(cookieName, DefaultCookieName);
// Assert
Assert.That(result, Is.Null);
}
[Test]
public void GetEnvelopeKeyOrDefault_ShouldReturnNull_WhenCookieNameIsUnrelated()
{
// Act
var result = CookieNames.GetEnvelopeKeyOrDefault("SomeOtherCookie", DefaultCookieName);
// Assert
Assert.That(result, Is.Null);
}
[Test]
public void TryGetEnvelopeKey_WithDefaultCookieName_ShouldReturnTrueAndKey_WhenCookieNameIsValid()
{
// Arrange
var cookieName = CookieNames.GetEnvelopeReceiverCookieName(Key); // uses "AuthToken" base
// Act
var success = CookieNames.TryGetEnvelopeKey(cookieName, out var key);
// Assert
Assert.Multiple(() =>
{
Assert.That(success, Is.True);
Assert.That(key, Is.EqualTo(Key));
});
}
[Test]
public void TryGetEnvelopeKey_WithDefaultCookieName_ShouldReturnFalse_WhenCookieNameHasWrongBase()
{
// Arrange
var cookieName = CookieNames.GetEnvelopeReceiverCookieName("OtherCookie", Key);
// Act
var success = CookieNames.TryGetEnvelopeKey(cookieName, out var key);
// Assert
Assert.Multiple(() =>
{
Assert.That(success, Is.False);
Assert.That(key, Is.Null);
});
}
[Test]
public void TryGetEnvelopeKey_ShouldReturnTrueAndKey_WhenCookieNameIsValid()
{
// Arrange
var cookieName = CookieNames.GetEnvelopeReceiverCookieName(DefaultCookieName, Key);
// Act
var success = CookieNames.TryGetEnvelopeKey(cookieName, DefaultCookieName, out var key);
// Assert
Assert.Multiple(() =>
{
Assert.That(success, Is.True);
Assert.That(key, Is.EqualTo(Key));
});
}
[Test]
public void TryGetEnvelopeKey_ShouldReturnFalse_WhenCookieNameHasWrongBase()
{
// Arrange
var cookieName = CookieNames.GetEnvelopeReceiverCookieName("OtherCookie", Key);
// Act
var success = CookieNames.TryGetEnvelopeKey(cookieName, DefaultCookieName, out var key);
// Assert
Assert.Multiple(() =>
{
Assert.That(success, Is.False);
Assert.That(key, Is.Null);
});
}
[Test]
public void TryGetEnvelopeKey_ShouldReturnFalse_WhenCookieNameIsUnrelated()
{
// Act
var success = CookieNames.TryGetEnvelopeKey("SomeOtherCookie", DefaultCookieName, out var key);
// Assert
Assert.Multiple(() =>
{
Assert.That(success, Is.False);
Assert.That(key, Is.Null);
});
}
[Test]
public void GetAndGetOrDefault_ShouldBeInverse_RoundTrip()
{
// Arrange
var cookieName = CookieNames.GetEnvelopeReceiverCookieName(DefaultCookieName, Key);
// Act
var extractedKey = CookieNames.GetEnvelopeKeyOrDefault(cookieName, DefaultCookieName);
// Assert
Assert.That(extractedKey, Is.EqualTo(Key));
}
}

View File

@@ -25,6 +25,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DigitalData.Auth.Claims\DigitalData.Auth.Claims.csproj" />
<ProjectReference Include="..\DigitalData.Auth.Client\DigitalData.Auth.Client.csproj" />
<ProjectReference Include="..\src\DigitalData.Auth.API\DigitalData.Auth.API.csproj" />
</ItemGroup>

View File

@@ -2,6 +2,7 @@
using DigitalData.Auth.API.Entities;
using DigitalData.Auth.API.Models;
using DigitalData.Auth.API.Services.Contracts;
using DigitalData.Auth.Claims;
using DigitalData.Core.Abstraction.Application;
using DigitalData.Core.Abstraction.Application.DTO;
using DigitalData.Core.Abstractions.Security.Extensions;
@@ -258,7 +259,7 @@ namespace DigitalData.Auth.API.Controllers
if (cookie)
{
var cookieOptions = consumer.CookieOptions ?? _apiParams.DefaultCookieOptions;
Response.Cookies.Append(_apiParams.DefaultCookieName, token, cookieOptions.Create(lifetime: descriptor.Lifetime));
Response.Cookies.Append(CookieNames.GetEnvelopeReceiverCookieName(_apiParams.DefaultCookieName, key), token, cookieOptions.Create(lifetime: descriptor.Lifetime));
return Ok();
}
else

View File

@@ -4,9 +4,9 @@
<TargetFrameworks>net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.4.0</Version>
<AssemblyVersion>1.4.0</AssemblyVersion>
<FileVersion>1.4.0</FileVersion>
<Version>1.4.1</Version>
<AssemblyVersion>1.4.1</AssemblyVersion>
<FileVersion>1.4.1</FileVersion>
</PropertyGroup>
<ItemGroup>