aboutsummaryrefslogtreecommitdiff
path: root/libs/VNLib.Plugins.Sessions.OAuth
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-07-28 19:34:23 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-07-28 19:34:23 -0400
commit34902c086d1707707b806864363cfaee317213e2 (patch)
treeeb2afb63a5400cad9a88ae5c3209bd0ab335ec24 /libs/VNLib.Plugins.Sessions.OAuth
parentf2dedded2a8646273c4dd13013b8334d64e02d6f (diff)
Squashed commit of the following:HEADmaster
commit a1ee522f7f5f0ab3cd268b0f42223700dd4d9dc8 Author: vnugent <public@vaughnnugent.com> Date: Thu Jul 4 23:57:14 2024 -0400 analyzer pass commit d650bac961dc927cd9b1b35816dab6e48c744ef9 Author: vnugent <public@vaughnnugent.com> Date: Fri Jun 21 17:07:54 2024 -0400 config validation updates commit 166e4b771f6f95c5093cf064ab47190bc2b33646 Merge: 4c973bb f2dedde Author: vnugent <public@vaughnnugent.com> Date: Wed May 22 15:33:54 2024 -0400 Merge branch 'master' into develop commit 4c973bb81d8cff22a77eb082611746713390c99b Author: vnugent <public@vaughnnugent.com> Date: Sun May 19 11:41:55 2024 -0400 feat: Update to follow latest core features commit 7118b66c4f2655db01fd061e43f5214d0dd891e8 Author: vnugent <public@vaughnnugent.com> Date: Thu May 2 15:47:22 2024 -0400 refactor: Moved session security middleware commit 97722f178f5e5107fcbdd1df4944a818fedf8722 Merge: f70c94e 84f81db Author: vnugent <public@vaughnnugent.com> Date: Sat Apr 20 12:13:23 2024 -0400 Merge branch 'master' into develop commit f70c94e948aa41e90d99f187d8a4791a726bc681 Author: vnugent <public@vaughnnugent.com> Date: Sat Apr 20 00:48:49 2024 -0400 fix: Missing session detach flag on close commit 2a2078b8cc3dd216c46419bce7577ae572317955 Author: vnugent <public@vaughnnugent.com> Date: Mon Apr 15 16:22:38 2024 -0400 fix: fixed bearer token header requirments from crashing
Diffstat (limited to 'libs/VNLib.Plugins.Sessions.OAuth')
-rw-r--r--libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionConfig.cs27
-rw-r--r--libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionProvider.cs6
2 files changed, 10 insertions, 23 deletions
diff --git a/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionConfig.cs b/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionConfig.cs
index 9e612d5..ab36e25 100644
--- a/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionConfig.cs
+++ b/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionConfig.cs
@@ -22,10 +22,10 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
-using System;
using System.Text.Json.Serialization;
using VNLib.Plugins.Extensions.Loading;
+using VNLib.Plugins.Extensions.Loading.Configuration;
namespace VNLib.Plugins.Sessions.OAuth
@@ -47,27 +47,12 @@ namespace VNLib.Plugins.Sessions.OAuth
[JsonPropertyName("access_token_type")]
public string TokenType { get; set; } = "Bearer";
- public void Validate()
+ public void OnValidate()
{
- if (MaxTokensPerApp < 1)
- {
- throw new ArgumentOutOfRangeException("max_tokens_per_app", "You must configure at least 1 Oatuh2 access token per application, or disable this plugin");
- }
-
- if (AccessTokenSize < 16)
- {
- throw new ArgumentOutOfRangeException("access_token_size", "You must configure an access token size of at least 16 bytes in length");
- }
-
- if (TokenLifeTimeSeconds < 1)
- {
- throw new ArgumentOutOfRangeException("token_valid_for_sec", "You must configure an access token lifetime");
- }
-
- if (string.IsNullOrWhiteSpace(CachePrefix))
- {
- throw new ArgumentException("You must specify a cache prefix", "cache_prefix");
- }
+ Validate.Range(MaxTokensPerApp, 1, int.MaxValue);
+ Validate.Range(AccessTokenSize, 16, int.MaxValue);
+ Validate.Range(TokenLifeTimeSeconds, 1, int.MaxValue);
+ Validate.NotNull(CachePrefix, "You must specify a cache prefix");
}
}
} \ No newline at end of file
diff --git a/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionProvider.cs b/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionProvider.cs
index bc06052..fe176d6 100644
--- a/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionProvider.cs
+++ b/libs/VNLib.Plugins.Sessions.OAuth/src/OAuth2SessionProvider.cs
@@ -71,6 +71,8 @@ namespace VNLib.Plugins.Sessions.OAuth
TokenStore = new(plugin.GetContextOptions());
_tokenTypeString = $"client_credential,{_tokenFactory.TokenType}";
+ _maxConnections = config.GetValueOrDefault("max_connections", p => p.GetUInt32(), 1000u);
+
//Schedule interval
plugin.ScheduleInterval(this, TimeSpan.FromMinutes(2));
@@ -168,7 +170,7 @@ namespace VNLib.Plugins.Sessions.OAuth
session.Invalidate();
//Clears important security variables
- InitNewSession(session, null);
+ InitNewSession(session, app: null);
}
return new SessionHandle(session, OnSessionReleases);
@@ -198,7 +200,7 @@ namespace VNLib.Plugins.Sessions.OAuth
await _sessions.CommitSessionAsync(newSession);
//Init new token result to pass to client
- return new OAuth2TokenResult()
+ return new OAuth2TokenResult
{
ExpiresSeconds = (int)_tokenFactory.SessionValidFor.TotalSeconds,
TokenType = _tokenFactory.TokenType,