aboutsummaryrefslogtreecommitdiff
path: root/plugins/VNLib.Plugins.Essentials.Accounts/src/Endpoints/KeepAliveEndpoint.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-01-14 16:32:04 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2023-01-14 16:32:04 -0500
commit1ce9119c2571b1e03f7e7b69fb3ef2e63ade97a6 (patch)
tree11ea3fafdc1f7e88319a3f3a174c2a89b69dbd48 /plugins/VNLib.Plugins.Essentials.Accounts/src/Endpoints/KeepAliveEndpoint.cs
parent551066ed9a255bd47c1c5789ec1998fda64bd5aa (diff)
AccountUtil + client token upgrade
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.Accounts/src/Endpoints/KeepAliveEndpoint.cs')
-rw-r--r--plugins/VNLib.Plugins.Essentials.Accounts/src/Endpoints/KeepAliveEndpoint.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.Accounts/src/Endpoints/KeepAliveEndpoint.cs b/plugins/VNLib.Plugins.Essentials.Accounts/src/Endpoints/KeepAliveEndpoint.cs
index fe5a65b..0ff0869 100644
--- a/plugins/VNLib.Plugins.Essentials.Accounts/src/Endpoints/KeepAliveEndpoint.cs
+++ b/plugins/VNLib.Plugins.Essentials.Accounts/src/Endpoints/KeepAliveEndpoint.cs
@@ -27,14 +27,19 @@ using System.Net;
using System.Text.Json;
using System.Collections.Generic;
+using VNLib.Utils.Extensions;
using VNLib.Plugins.Essentials.Endpoints;
+using VNLib.Plugins.Essentials.Extensions;
using VNLib.Plugins.Extensions.Loading;
+
namespace VNLib.Plugins.Essentials.Accounts.Endpoints
{
[ConfigurationName("keepalive_endpoint")]
internal sealed class KeepAliveEndpoint : ProtectedWebEndpoint
{
+ readonly TimeSpan tokenRegenTime;
+
/*
* Endpoint does not use a log, so IniPathAndLog is never called
* and path verification happens verbosly
@@ -43,6 +48,8 @@ namespace VNLib.Plugins.Essentials.Accounts.Endpoints
{
string? path = config["path"].GetString();
+ tokenRegenTime = config["token_refresh_sec"].GetTimeSpan(TimeParseType.Seconds);
+
InitPathAndLog(path, pbase.Log);
}
@@ -56,6 +63,24 @@ namespace VNLib.Plugins.Essentials.Accounts.Endpoints
//Allow post to update user's credentials
protected override VfReturnType Post(HttpEntity entity)
{
+ //Get the last token update
+ DateTimeOffset lastTokenUpdate = entity.Session.LastTokenUpgrade();
+
+ //See if its expired
+ if (lastTokenUpdate.Add(tokenRegenTime) < entity.RequestedTimeUtc)
+ {
+ //if so updaet token
+ WebMessage webm = new()
+ {
+ Token = entity.RegenerateClientToken(),
+ Success = true
+ };
+
+ //Send the update message to the client
+ entity.CloseResponse(webm);
+ return VfReturnType.VirtualSkip;
+ }
+
//Return okay
entity.CloseResponse(HttpStatusCode.OK);
return VfReturnType.VirtualSkip;