24 lines
635 B
C#
24 lines
635 B
C#
using System.Text.Json;
|
|
|
|
namespace MxGateway.Server.Security.Authentication;
|
|
|
|
public static class ApiKeyScopeSerializer
|
|
{
|
|
public static string Serialize(IReadOnlySet<string> scopes)
|
|
{
|
|
return JsonSerializer.Serialize(scopes.Order(StringComparer.Ordinal));
|
|
}
|
|
|
|
public static IReadOnlySet<string> Deserialize(string value)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
return new HashSet<string>(StringComparer.Ordinal);
|
|
}
|
|
|
|
string[]? scopes = JsonSerializer.Deserialize<string[]>(value);
|
|
|
|
return new HashSet<string>(scopes ?? [], StringComparer.Ordinal);
|
|
}
|
|
}
|