fix activation registration after local-network-access policy introduction

This commit is contained in:
Gary Sharp
2025-12-29 13:14:52 +11:00
parent f975c55b8a
commit 4e7c7c117b
12 changed files with 128 additions and 268 deletions
@@ -42,6 +42,24 @@ namespace Disco.Services.Interop.DiscoServices
public Uri GetCallbackUrl()
=> new Uri(DiscoServiceHelpers.ActivationServiceUrl, "/api/callback");
public string CalculateCallbackProof(Guid correlationId, string userId, long timestamp)
{
var deploymentId = Guid.Parse(database.DiscoConfiguration.DeploymentId);
var secret = Guid.Parse(database.DiscoConfiguration.DeploymentSecret);
using (var hmac = new HMACSHA256(secret.ToByteArray()))
{
var data = new MemoryStream();
data.Write(deploymentId.ToByteArray(), 0, 16);
data.Write(correlationId.ToByteArray(), 0, 16);
var userIdBytes = Encoding.UTF8.GetBytes(userId);
data.Write(BitConverter.GetBytes(userIdBytes.Length), 0, 4);
data.Write(userIdBytes, 0, userIdBytes.Length);
data.Write(BitConverter.GetBytes(timestamp), 0, 8);
var hash = hmac.ComputeHash(data.ToArray());
return Convert.ToBase64String(hash).TrimEnd('=').Replace('+', '-').Replace('/', '_');
}
}
/// <summary>
/// Begin the activation process
/// </summary>
@@ -43,7 +43,10 @@ namespace Disco.Services.Interop.DiscoServices
connection.Closed += ex =>
{
SystemLog.LogException("Online Services: Connection Closed", ex);
if (ex != null)
SystemLog.LogException("Online Services: Connection Closed", ex);
else
SystemLog.LogInformation("Online Services: Connection Closed");
return Task.CompletedTask;
};
connection.Reconnected += connectionId =>
@@ -53,7 +56,11 @@ namespace Disco.Services.Interop.DiscoServices
};
connection.Reconnecting += ex =>
{
SystemLog.LogInformation("Online Services: Connection Reconnecting");
if (ex != null)
SystemLog.LogException("Online Services: Connection Reconnecting", ex);
else
SystemLog.LogInformation("Online Services: Connection Reconnecting");
return Task.CompletedTask;
};
}