aboutsummaryrefslogtreecommitdiff
path: root/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs')
-rw-r--r--Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs20
1 files changed, 3 insertions, 17 deletions
diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs b/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs
index 7b07f46..56283c6 100644
--- a/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs
+++ b/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Essentials.Oauth
@@ -40,17 +40,8 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens
/// that allows for communicating token information to
/// plugins
/// </summary>
- public sealed class TokenStore : ITokenManager
+ public sealed class TokenStore(DbContextOptions Options) : ITokenManager
{
- private readonly DbContextOptions Options;
-
- /// <summary>
- /// Initializes a new <see cref="TokenStore"/> that will make quries against
- /// the supplied <see cref="DbContextOptions"/>
- /// </summary>
- /// <param name="options">The DB connection context</param>
- public TokenStore(DbContextOptions options) => Options = options;
-
/// <summary>
/// Inserts a new token into the table for a specified application id. Also determines if
/// the user has reached the maximum number of allowed tokens
@@ -68,7 +59,6 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens
public async Task<ERRNO> InsertTokenAsync(string token, string appId, string? refreshToken, int maxTokens, CancellationToken cancellation)
{
await using UserAppContext ctx = new (Options);
- await ctx.OpenTransactionAsync(cancellation);
//Check active token count
int count = await (from t in ctx.OAuthTokens
@@ -108,13 +98,12 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens
public async Task RevokeTokenAsync(string token, CancellationToken cancellation)
{
await using UserAppContext ctx = new (Options);
- await ctx.OpenTransactionAsync(cancellation);
//Get the token from the db if it exists
ActiveToken? at = await (from t in ctx.OAuthTokens
where t.Id == token
select t)
.FirstOrDefaultAsync(cancellation);
- if(at == null)
+ if(at is null)
{
return;
}
@@ -133,7 +122,6 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens
public async Task<IReadOnlyCollection<ActiveToken>> CleanupExpiredTokensAsync(DateTime validAfter, CancellationToken cancellation)
{
await using UserAppContext ctx = new (Options);
- await ctx.OpenTransactionAsync(cancellation);
//Get the token from the db if it exists
ActiveToken[] at = await (from t in ctx.OAuthTokens
where t.Created < validAfter
@@ -151,7 +139,6 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens
public async Task RevokeTokensAsync(IReadOnlyCollection<string> tokens, CancellationToken cancellation = default)
{
await using UserAppContext ctx = new (Options);
- await ctx.OpenTransactionAsync(cancellation);
//Get all tokenes that are contained in the collection
ActiveToken[] at = await (from t in ctx.OAuthTokens
where tokens.Contains(t.Id)
@@ -168,7 +155,6 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens
async Task ITokenManager.RevokeTokensForAppAsync(string appId, CancellationToken cancellation)
{
await using UserAppContext ctx = new (Options);
- await ctx.OpenTransactionAsync(cancellation);
//Get the token from the db if it exists
ActiveToken[] at = await (from t in ctx.OAuthTokens
where t.ApplicationId == appId