diff options
author | vman <public@vaughnnugent.com> | 2022-12-15 01:45:03 -0500 |
---|---|---|
committer | vman <public@vaughnnugent.com> | 2022-12-15 01:45:03 -0500 |
commit | 1f2b3530ebeafa162fe4df41e691c33cb2ff0009 (patch) | |
tree | 7f60d7c761cee2df89303c3ef0550743790a63e2 /Libs/VNLib.Plugins.Essentials.Sessions.OAuth/OAuth2SessionProvider.cs | |
parent | a0d5a8d40de9806e21e64475e3297a2a84effe22 (diff) |
JWK sigs, session cleanup v1
Diffstat (limited to 'Libs/VNLib.Plugins.Essentials.Sessions.OAuth/OAuth2SessionProvider.cs')
-rw-r--r-- | Libs/VNLib.Plugins.Essentials.Sessions.OAuth/OAuth2SessionProvider.cs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Libs/VNLib.Plugins.Essentials.Sessions.OAuth/OAuth2SessionProvider.cs b/Libs/VNLib.Plugins.Essentials.Sessions.OAuth/OAuth2SessionProvider.cs index d698c81..106029f 100644 --- a/Libs/VNLib.Plugins.Essentials.Sessions.OAuth/OAuth2SessionProvider.cs +++ b/Libs/VNLib.Plugins.Essentials.Sessions.OAuth/OAuth2SessionProvider.cs @@ -55,18 +55,20 @@ namespace VNLib.Plugins.Essentials.Sessions.OAuth private readonly IOauthSessionIdFactory factory; private readonly TokenStore TokenStore; - - public OAuth2SessionProvider(FBMClient client, int maxCacheItems, IOauthSessionIdFactory idFactory, DbContextOptions dbCtx) + private readonly uint MaxConnections; + + public OAuth2SessionProvider(FBMClient client, int maxCacheItems, uint maxConnections, IOauthSessionIdFactory idFactory, DbContextOptions dbCtx) : base(client, maxCacheItems) { factory = idFactory; TokenStore = new(dbCtx); + MaxConnections = maxConnections; } ///<inheritdoc/> - protected override RemoteSession SessionCtor(string sessionId) => new OAuth2Session(sessionId, Client, BackgroundTimeout, InvlidatateCache); + protected override RemoteSession SessionCtor(string sessionId) => new OAuth2Session(sessionId, Client, BackgroundTimeout, InvalidatateCache); - private void InvlidatateCache(OAuth2Session session) + private void InvalidatateCache(OAuth2Session session) { lock (CacheLock) { @@ -91,6 +93,14 @@ namespace VNLib.Plugins.Essentials.Sessions.OAuth return SessionHandle.Empty; } + //Limit max number of waiting clients + if (WaitingConnections > MaxConnections) + { + //Set 503 for temporary unavail + entity.CloseResponse(System.Net.HttpStatusCode.ServiceUnavailable); + return new SessionHandle(null, FileProcessArgs.VirtualSkip, null); + } + //Recover the session RemoteSession session = await base.GetSessionAsync(entity, sessionId, cancellationToken); @@ -174,14 +184,14 @@ namespace VNLib.Plugins.Essentials.Sessions.OAuth /* - * Interval for remving expired tokens + * Interval for removing expired tokens */ ///<inheritdoc/> async Task IIntervalScheduleable.OnIntervalAsync(ILogProvider log, CancellationToken cancellationToken) { //Calculate valid token time - DateTimeOffset validAfter = DateTimeOffset.UtcNow.Subtract(factory.SessionValidFor); + DateTime validAfter = DateTime.UtcNow.Subtract(factory.SessionValidFor); //Remove tokens from db store IReadOnlyCollection<ActiveToken> revoked = await TokenStore.CleanupExpiredTokensAsync(validAfter, cancellationToken); //exception list |