Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Intersect.Server/Web/Net7/ApiService.AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ private static void ValidateConfiguration()
TokenGenerationOptions.DefaultRefreshTokenLifetime;
}

if (apiConfiguration.TokenGenerationOptions.SecretData.Length < 64)
if (apiConfiguration.TokenGenerationOptions.Secret.Length < 128)
{
apiConfiguration.TokenGenerationOptions.SecretData = default;
apiConfiguration.TokenGenerationOptions.Secret = default;
if (apiConfiguration.TokenGenerationOptions.Secret == default)
{
throw new UnreachableException("This should be automatically re-generated.");
Expand Down
22 changes: 20 additions & 2 deletions Intersect.Server/Web/Net7/Configuration/TokenGenerationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Text;
using Intersect.Logging;

namespace Intersect.Server.Web.Configuration;

Expand Down Expand Up @@ -29,7 +29,25 @@ public class TokenGenerationOptions
public string Secret
{
get => Convert.ToHexString(SecretData ??= RandomNumberGenerator.GetBytes(64));
set => SecretData = string.IsNullOrWhiteSpace(value) ? default : Convert.FromHexString(value);
set
{
if (string.IsNullOrWhiteSpace(value))
{
SecretData = default;
return;
}

try
{
value = value.Trim();
SecretData = Convert.FromHexString(value.Trim());
}
catch (Exception exception)
{
Log.Error(exception, $"Failed to parse secret (should be hex), value was {value.Length} characters long");
SecretData = default;
}
}
}

[Newtonsoft.Json.JsonIgnore]
Expand Down
Loading