diff options
author | vnugent <public@vaughnnugent.com> | 2023-08-28 22:00:43 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-08-28 22:00:43 -0400 |
commit | 579204edb43e0d44f064cc5243bf14939f3f0895 (patch) | |
tree | a8c75531c40a311da7877679a7dd9655e8e9faf6 /Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens | |
parent | b447f0cb29e54c988dd64f28e87fd9ca81127b11 (diff) |
Data extensions updates
Diffstat (limited to 'Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens')
3 files changed, 49 insertions, 25 deletions
diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/ActiveToken.cs b/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/ActiveToken.cs index 8e8fb5e..0cb7f6f 100644 --- a/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/ActiveToken.cs +++ b/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/ActiveToken.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.Oauth @@ -28,13 +28,28 @@ using VNLib.Plugins.Extensions.Data; namespace VNLib.Plugins.Essentials.Oauth.Tokens { + /// <summary> + /// Represents a token record in the database + /// </summary> public class ActiveToken : DbModelBase { + ///<inheritdoc/> public override string Id { get; set; } = string.Empty; + + ///<inheritdoc/> public override DateTime Created { get; set; } + + ///<inheritdoc/> public override DateTime LastModified { get; set; } + /// <summary> + /// A ID of the applicaiton this token was issued for + /// </summary> public string? ApplicationId { get; set; } + + /// <summary> + /// An optional OAuth2 refresh token, used for refreshing access tokens + /// </summary> public string? RefreshToken { get; set; } } } diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/IOAuth2TokenResult.cs b/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/IOAuth2TokenResult.cs index 0a4cc31..bd9ffce 100644 --- a/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/IOAuth2TokenResult.cs +++ b/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/IOAuth2TokenResult.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Essentials.Oauth @@ -29,10 +29,29 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens /// </summary> public interface IOAuth2TokenResult { + /// <summary> + /// An optional token that can be used to identify the user + /// </summary> string? IdentityToken { get; } + + /// <summary> + /// The access token, used for authenticating requests + /// </summary> string? AccessToken { get; } + + /// <summary> + /// An optional OAuth2 refresh token, used for refreshing access tokens + /// </summary> string? RefreshToken { get; } + + /// <summary> + /// The type of token, usually "Bearer" + /// </summary> string? TokenType { get; } + + /// <summary> + /// The number of seconds until the access token expires + /// </summary> int ExpiresSeconds { get; } } }
\ No newline at end of file diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs b/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs index f160a79..7b07f46 100644 --- a/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs +++ b/Libs/VNLib.Plugins.Essentials.Oauth/src/Tokens/TokenStore.cs @@ -92,20 +92,11 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens Created = now, LastModified = now, }; + //Add token to store - ctx.OAuthTokens.Add(newToken); - //commit changes - ERRNO result = await ctx.SaveChangesAsync(cancellation); - if (result) - { - //End transaction - await ctx.CommitTransactionAsync(cancellation); - } - else - { - await ctx.RollbackTransctionAsync(cancellation); - } - return result; + ctx.Add(newToken); + + return await ctx.SaveAndCloseAsync(true, cancellation); } /// <summary> @@ -128,11 +119,11 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens return; } //delete token - ctx.OAuthTokens.Remove(at); + ctx.Remove(at); //Save changes - await ctx.SaveChangesAsync(cancellation); - await ctx.CommitTransactionAsync(cancellation); + await ctx.SaveAndCloseAsync(true, cancellation); } + /// <summary> /// Removes all token entires that were created before the specified time /// </summary> @@ -150,12 +141,12 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens .ToArrayAsync(cancellation); //delete token - ctx.OAuthTokens.RemoveRange(at); + ctx.RemoveRange(at); //Save changes - int count = await ctx.SaveChangesAsync(cancellation); - await ctx.CommitTransactionAsync(cancellation); + await ctx.SaveAndCloseAsync(true, cancellation); return at; } + ///<inheritdoc/> public async Task RevokeTokensAsync(IReadOnlyCollection<string> tokens, CancellationToken cancellation = default) { @@ -170,9 +161,9 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens //delete token ctx.OAuthTokens.RemoveRange(at); //Save changes - await ctx.SaveChangesAsync(cancellation); - await ctx.CommitTransactionAsync(cancellation); + await ctx.SaveAndCloseAsync(true, cancellation); } + ///<inheritdoc/> async Task ITokenManager.RevokeTokensForAppAsync(string appId, CancellationToken cancellation) { @@ -190,8 +181,7 @@ namespace VNLib.Plugins.Essentials.Oauth.Tokens t.Created = DateTime.MinValue; } //Save changes - await ctx.SaveChangesAsync(cancellation); - await ctx.CommitTransactionAsync(cancellation); + await ctx.SaveAndCloseAsync(true, cancellation); } } } |