Skip to content

Commit

Permalink
Reimplemented Tokens. (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 authored Dec 20, 2024
1 parent 6910b3e commit 2f6c3a2
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lib/Logitar.Identity.Core/Logitar.Identity.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<PackageReference Include="Logitar.Security" Version="7.0.0" />
<PackageReference Include="MediatR.Contracts" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.3.0" />
<PackageReference Include="NodaTime" Version="3.2.0" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>
Expand All @@ -56,6 +57,7 @@
<Using Include="System.Diagnostics.CodeAnalysis" />
<Using Include="System.Globalization" />
<Using Include="System.Linq" />
<Using Include="System.Security.Claims" />
<Using Include="System.Text" />
<Using Include="System.Text.Json.Serialization" />
<Using Include="System.Threading" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.IdentityModel.Tokens;

namespace Logitar.Identity.Domain.Tokens;
namespace Logitar.Identity.Core.Tokens;

/// <summary>
/// Represents token creation options.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Logitar.Identity.Domain.Tokens;
namespace Logitar.Identity.Core.Tokens;

/// <summary>
/// Represents token creation parameters.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.IdentityModel.Tokens;

namespace Logitar.Identity.Domain.Tokens;
namespace Logitar.Identity.Core.Tokens;

/// <summary>
/// Represents a created token.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Logitar.Identity.Domain.Tokens;
namespace Logitar.Identity.Core.Tokens;

/// <summary>
/// Defines a token blacklist.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Logitar.Identity.Domain.Tokens;
namespace Logitar.Identity.Core.Tokens;

/// <summary>
/// Defines methods to manage tokens.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.IdentityModel.Tokens;

namespace Logitar.Identity.Domain.Tokens;
namespace Logitar.Identity.Core.Tokens;

/// <summary>
/// The exception raised when a validated security token is blacklisted.
Expand All @@ -10,14 +10,14 @@ public class SecurityTokenBlacklistedException : SecurityTokenValidationExceptio
/// <summary>
/// A generic error message for this exception.
/// </summary>
public const string ErrorMessage = "The security token is blacklisted.";
private const string ErrorMessage = "The security token is blacklisted.";

/// <summary>
/// Gets or sets the list of blacklisted token identifiers.
/// </summary>
public IEnumerable<string> BlacklistedIds
public IReadOnlyCollection<string> BlacklistedIds
{
get => (IEnumerable<string>)Data[nameof(BlacklistedIds)]!;
get => (IReadOnlyCollection<string>)Data[nameof(BlacklistedIds)]!;
private set => Data[nameof(BlacklistedIds)] = value;
}

Expand All @@ -27,20 +27,23 @@ public IEnumerable<string> BlacklistedIds
/// <param name="blacklistedIds">The list of the blacklisted token identifiers.</param>
public SecurityTokenBlacklistedException(IEnumerable<string> blacklistedIds) : base(BuildMessage(blacklistedIds))
{
BlacklistedIds = blacklistedIds;
BlacklistedIds = blacklistedIds.ToArray();
}

/// <summary>
/// Builds the exception message.
/// </summary>
/// <param name="blacklistedIds">The list of the blacklisted token identifiers.</param>
/// <returns>The exception message.</returns>
private static string BuildMessage(IEnumerable<string> blacklistedIds)
{
StringBuilder message = new();

message.AppendLine(ErrorMessage);
message.AppendLine("BlacklistedIds:");
message.Append(nameof(BlacklistedIds)).Append(':').AppendLine();
foreach (string blacklistedId in blacklistedIds)
{
message.Append(" - ").Append(blacklistedId).AppendLine();
}

return message.ToString();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Logitar.Identity.Domain.Tokens;
namespace Logitar.Identity.Core.Tokens;

/// <summary>
/// Represents token validation options.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Logitar.Identity.Domain.Tokens;
namespace Logitar.Identity.Core.Tokens;

/// <summary>
/// Represents token validation parameters.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.IdentityModel.Tokens;

namespace Logitar.Identity.Domain.Tokens;
namespace Logitar.Identity.Core.Tokens;

/// <summary>
/// Represents a validated token.
Expand Down

0 comments on commit 2f6c3a2

Please sign in to comment.