From ef98ef0329d6ee8cec7f040f6c472dc1ea68e8dd Mon Sep 17 00:00:00 2001 From: vman Date: Fri, 18 Nov 2022 17:43:57 -0500 Subject: Add project files. --- .../Applications/Applications.cs | 260 +++++++++++++++++++++ .../Applications/UserAppContext.cs | 19 ++ .../Applications/UserApplication.cs | 133 +++++++++++ .../Tokens/ActiveToken.cs | 16 ++ .../Tokens/IOAuth2TokenResult.cs | 14 ++ .../Tokens/ITokenManager.cs | 27 +++ .../Tokens/TokenStore.cs | 171 ++++++++++++++ .../VNLib.Plugins.Essentials.Oauth.csproj | 45 ++++ .../VNLib.Plugins.Essentials.Oauth.xml | 155 ++++++++++++ 9 files changed, 840 insertions(+) create mode 100644 Libs/VNLib.Plugins.Essentials.Oauth/Applications/Applications.cs create mode 100644 Libs/VNLib.Plugins.Essentials.Oauth/Applications/UserAppContext.cs create mode 100644 Libs/VNLib.Plugins.Essentials.Oauth/Applications/UserApplication.cs create mode 100644 Libs/VNLib.Plugins.Essentials.Oauth/Tokens/ActiveToken.cs create mode 100644 Libs/VNLib.Plugins.Essentials.Oauth/Tokens/IOAuth2TokenResult.cs create mode 100644 Libs/VNLib.Plugins.Essentials.Oauth/Tokens/ITokenManager.cs create mode 100644 Libs/VNLib.Plugins.Essentials.Oauth/Tokens/TokenStore.cs create mode 100644 Libs/VNLib.Plugins.Essentials.Oauth/VNLib.Plugins.Essentials.Oauth.csproj create mode 100644 Libs/VNLib.Plugins.Essentials.Oauth/VNLib.Plugins.Essentials.Oauth.xml (limited to 'Libs') diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/Applications/Applications.cs b/Libs/VNLib.Plugins.Essentials.Oauth/Applications/Applications.cs new file mode 100644 index 0000000..850ccba --- /dev/null +++ b/Libs/VNLib.Plugins.Essentials.Oauth/Applications/Applications.cs @@ -0,0 +1,260 @@ +using System; +using System.Data; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using System.Collections.Generic; + +using Microsoft.EntityFrameworkCore; + +using VNLib.Hashing; +using VNLib.Utils; +using VNLib.Utils.Memory; +using VNLib.Plugins.Extensions.Data; +using VNLib.Plugins.Essentials.Accounts; +using VNLib.Plugins.Essentials.Oauth.Tokens; + +namespace VNLib.Plugins.Essentials.Oauth.Applications +{ + /// + /// A DbStore for s for OAuth2 client applications + /// + public sealed partial class Applications : DbStore + { + public const int SECRET_SIZE = 32; + public const int CLIENT_ID_SIZE = 16; + + private readonly PasswordHashing SecretHashing; + private readonly DbContextOptions ConextOptions; + private readonly ITokenManager TokenStore; + + /// + /// Initializes a new data store + /// uisng the specified EFCore object. + /// + /// EFCore context options for connecting to a remote data-store + /// A structure for hashing client secrets + public Applications(DbContextOptions conextOptions, PasswordHashing secretHashing) + { + this.ConextOptions = conextOptions; + this.SecretHashing = secretHashing; + this.TokenStore = new TokenStore(conextOptions); + } + + + /// + /// Updates the secret of an application, and if successful returns the new raw secret data + /// + /// The user-id of that owns the application + /// The id of the application to update + /// A task that resolves to the raw secret that was used to generate the hash, or null if the operation failed + public async Task UpdateSecretAsync(string userId, string appId) + { + /* + * Delete open apps first, incase there are any issues, worse case + * the user's will have to re-authenticate. + * + * If we delete tokens after update, the user wont see the new + * secret and may lose access to the updated app, not a big deal + * but avoidable. + */ + await TokenStore.RevokeTokensForAppAsync(appId, CancellationToken.None); + //Generate the new secret + PrivateString secret = GenerateSecret(); + //Hash the secret + using PrivateString secretHash = SecretHashing.Hash(secret); + //Open new db context + await using UserAppContext Database = new(ConextOptions); + //Open transaction + await Database.OpenTransactionAsync(); + //Get the app to update the secret on + UserApplication? app = await (from ap in Database.OAuthApps + where ap.UserId == userId && ap.Id == appId + select ap) + .SingleOrDefaultAsync(); + if (app == null) + { + return null; + } + //Store the new secret hash + app.SecretHash = (string)secretHash; + //Save changes + if (await Database.SaveChangesAsync() <= 0) + { + return null; + } + //Commit transaction + await Database.CommitTransactionAsync(); + //return the raw secret + return secret; + } + + /// + /// Attempts to retreive an application by the specified client id and compares the raw secret against the + /// stored secret hash. + /// + /// The clientid of the application to search + /// The secret to compare against + /// True if the application was found and the secret matches the stored secret, false if the appliation was not found or the secret does not match + public async Task VerifyAppAsync(string clientId, PrivateString secret) + { + UserApplication? app; + //Open new db context + await using (UserAppContext Database = new(ConextOptions)) + { + //Open transaction + await Database.OpenTransactionAsync(); + //Get the application with its secret + app = await (from userApp in Database.OAuthApps + where userApp.ClientId == clientId + select userApp) + .FirstOrDefaultAsync(); + //commit the transaction + await Database.CommitTransactionAsync(); + } + //make sure app exists + if (string.IsNullOrWhiteSpace(app?.UserId) || !app.ClientId!.Equals(clientId, StringComparison.Ordinal)) + { + //Not found or not valid + return null; + } + //Convert the secret hash to a private string so it will be cleaned up + using PrivateString secretHash = (PrivateString)app.SecretHash!; + //Verify the secret against the hash + if (SecretHashing.Verify(secretHash, secret)) + { + app.SecretHash = null; + //App was successfully verified + return app; + } + //Not found or not valid + return null; + } + /// + public override async Task DeleteAsync(params string[] specifiers) + { + //get app id to remove tokens from + string appId = specifiers[0]; + //Delete app from store + ERRNO result = await base.DeleteAsync(specifiers); + if(result) + { + //Delete active tokens + await TokenStore.RevokeTokensForAppAsync(appId, CancellationToken.None); + } + return result; + } + + /// + /// Generates a client application secret using the library + /// + /// The RNG secret + public static PrivateString GenerateSecret() => (PrivateString)RandomHash.GetRandomHex(SECRET_SIZE).ToLower()!; + /// + /// Creates and initializes a new with a random clientid and + /// secret that must be disposed + /// + /// The new record to create + /// The result of the operation + public override async Task CreateAsync(UserApplication record) + { + record.RawSecret = GenerateSecret(); + //Hash the secret + using PrivateString secretHash = SecretHashing.Hash(record.RawSecret); + record.ClientId = GenerateClientID(); + record.SecretHash = (string)secretHash; + //Wait for the rescord to be created before wiping the secret + return await base.CreateAsync(record); + } + + /// + /// Generates a new client ID using the library + /// + /// The new client ID + public static string GenerateClientID() => RandomHash.GetRandomHex(CLIENT_ID_SIZE).ToLower(); + /// + public override string RecordIdBuilder => RandomHash.GetRandomHex(CLIENT_ID_SIZE).ToLower(); + /// + public override TransactionalDbContext NewContext() => new UserAppContext(ConextOptions); + /// + protected override IQueryable AddOrUpdateQueryBuilder(TransactionalDbContext context, UserApplication record) + { + UserAppContext ctx = (context as UserAppContext)!; + //get a single record by the id for the specific user + return from userApp in ctx.OAuthApps + where userApp.UserId == record.UserId + && userApp.Id == record.Id + select userApp; + } + /// + protected override void OnRecordUpdate(UserApplication newRecord, UserApplication currentRecord) + { + currentRecord.AppDescription = newRecord.AppDescription; + currentRecord.AppName = newRecord.AppName; + } + /// + protected override IQueryable GetCollectionQueryBuilder(TransactionalDbContext context, string userId) + { + UserAppContext ctx = (context as UserAppContext)!; + //Get the user's applications based on their userid + return from userApp in ctx.OAuthApps + where userApp.UserId == userId + orderby userApp.Created ascending + select new UserApplication + { + AppDescription = userApp.AppDescription, + Id = userApp.Id, + AppName = userApp.AppName, + ClientId = userApp.ClientId, + Created = userApp.Created, + Permissions = userApp.Permissions + }; + } + /// + protected override IQueryable GetCollectionQueryBuilder(TransactionalDbContext context, params string[] args) + { + return GetCollectionQueryBuilder(context, args[0]); + } + /// + protected override IQueryable GetSingleQueryBuilder(TransactionalDbContext context, params string[] constraints) + { + string appId = constraints[0]; + string userId = constraints[1]; + UserAppContext ctx = (context as UserAppContext)!; + //Query to get a new single application with limit results output + return from userApp in ctx.OAuthApps + where userApp.UserId == userId + && userApp.Id == appId + select new UserApplication + { + AppDescription = userApp.AppDescription, + Id = userApp.Id, + AppName = userApp.AppName, + ClientId = userApp.ClientId, + Created = userApp.Created, + Permissions = userApp.Permissions, + Version = userApp.Version + }; + } + /// + protected override IQueryable GetSingleQueryBuilder(TransactionalDbContext context, UserApplication record) + { + //Use the query for single record with the other record's userid and record id + return GetSingleQueryBuilder(context, record.Id, record.UserId); + } + /// + protected override IQueryable UpdateQueryBuilder(TransactionalDbContext context, UserApplication record) + { + UserAppContext ctx = (context as UserAppContext)!; + return from userApp in ctx.OAuthApps + where userApp.UserId == record.UserId && userApp.Id == record.Id + select userApp; + } + + //DO NOT ALLOW PAGINATION YET + public override Task GetPageAsync(ICollection collection, int page, int limit) + { + throw new NotSupportedException(); + } + } +} \ No newline at end of file diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/Applications/UserAppContext.cs b/Libs/VNLib.Plugins.Essentials.Oauth/Applications/UserAppContext.cs new file mode 100644 index 0000000..5a24b49 --- /dev/null +++ b/Libs/VNLib.Plugins.Essentials.Oauth/Applications/UserAppContext.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; + + +using VNLib.Plugins.Extensions.Data; +using VNLib.Plugins.Essentials.Oauth.Tokens; + +namespace VNLib.Plugins.Essentials.Oauth.Applications +{ + internal class UserAppContext : TransactionalDbContext + { + public DbSet OAuthApps { get; set; } + public DbSet OAuthTokens { get; set; } +#nullable disable + public UserAppContext(DbContextOptions options) : base(options) + { + + } + } +} \ No newline at end of file diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/Applications/UserApplication.cs b/Libs/VNLib.Plugins.Essentials.Oauth/Applications/UserApplication.cs new file mode 100644 index 0000000..1fa7671 --- /dev/null +++ b/Libs/VNLib.Plugins.Essentials.Oauth/Applications/UserApplication.cs @@ -0,0 +1,133 @@ +using System; +using System.Text.Json; +using System.ComponentModel; +using System.Collections.Generic; +using System.Text.Json.Serialization; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +using VNLib.Utils.Memory; +using VNLib.Utils.Extensions; +using VNLib.Hashing.IdentityUtility; +using VNLib.Plugins.Extensions.Data; +using VNLib.Plugins.Extensions.Data.Abstractions; + +using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute; + + +namespace VNLib.Plugins.Essentials.Oauth.Applications +{ + /// + /// + /// + [Index(nameof(ClientId), IsUnique = true)] + public class UserApplication : DbModelBase, IUserEntity, IJsonOnDeserialized + { + /// + [Key, Required] + public override string? Id { get; set; } + /// + public override DateTime Created { get; set; } + /// + public override DateTime LastModified { get; set; } + + /// + [Required] + [JsonIgnore] + public string? UserId { get; set; } + + /// + /// The OAuth2 application's associated client-id + /// + [Required] + [JsonPropertyName("client_id")] + public string? ClientId { get; set; } + + /// + /// The hash of the application's secret (no json-serializable) + /// + [JsonIgnore] + [MaxLength(1000)] + public string? SecretHash { get; set; } + + /// + /// The user-defined name of the application + /// + [DisplayName("Application Name")] + [JsonPropertyName("name")] + public string? AppName { get; set; } + + /// + /// The user-defined description for the application + /// + [JsonPropertyName("description")] + [DisplayName("Application Description")] + public string? AppDescription { get; set; } + + /// + /// The permissions for the application + /// + [JsonPropertyName("permissions")] + [Column("permissions")] + public string? Permissions { get; set; } + + + [NotMapped] + [JsonIgnore] + public PrivateString? RawSecret { get; set; } + + void IJsonOnDeserialized.OnDeserialized() + { + Id = Id?.Trim(); + ClientId = ClientId?.Trim(); + UserId = UserId?.Trim(); + AppName = AppName?.Trim(); + AppDescription = AppDescription?.Trim(); + Permissions = Permissions?.Trim(); + } + + + /// + /// Creates a new instance + /// from the supplied assuming + /// JWT format + /// + /// The application JWT payalod element + /// The recovered application + public static UserApplication FromJwtDoc(in JsonElement appEl) + { + return new() + { + UserId = appEl.GetPropString("sub"), + ClientId = appEl.GetPropString("azp"), + Id = appEl.GetPropString("appid"), + Permissions = appEl.GetPropString("scope"), + }; + } + /// + /// Stores the + /// + /// The application to serialze to JWT format + /// Jwt dictionary payload + public static void ToJwtDict(UserApplication app, IDictionary dict) + { + dict["appid"] = app.Id; + dict["azp"] = app.ClientId; + dict["sub"] = app.UserId; + dict["scope"] = app.Permissions; + } + + /// + /// Stores the + /// + /// + /// JW payload parameter + public static void ToJwtPayload(UserApplication app, in JwtPayload payload) + { + payload["appid"] = app.Id; + payload["azp"] = app.ClientId; + payload["sub"] = app.UserId; + payload["scope"] = app.Permissions; + } + } +} \ No newline at end of file diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/ActiveToken.cs b/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/ActiveToken.cs new file mode 100644 index 0000000..29760c2 --- /dev/null +++ b/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/ActiveToken.cs @@ -0,0 +1,16 @@ +using System; + +using VNLib.Plugins.Extensions.Data; + +namespace VNLib.Plugins.Essentials.Oauth.Tokens +{ + public class ActiveToken : DbModelBase + { + public override string Id { get; set; } + public override DateTime Created { get; set; } + public override DateTime LastModified { get; set; } + + public string? ApplicationId { get; set; } + public string? RefreshToken { get; set; } + } +} diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/IOAuth2TokenResult.cs b/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/IOAuth2TokenResult.cs new file mode 100644 index 0000000..a96810f --- /dev/null +++ b/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/IOAuth2TokenResult.cs @@ -0,0 +1,14 @@ +namespace VNLib.Plugins.Essentials.Oauth.Tokens +{ + /// + /// The result of an OAuth2Token creation + /// + public interface IOAuth2TokenResult + { + string? IdentityToken { get; } + string? AccessToken { get; } + string? RefreshToken { get; } + string? TokenType { get; } + int ExpiresSeconds { get; } + } +} \ No newline at end of file diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/ITokenManager.cs b/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/ITokenManager.cs new file mode 100644 index 0000000..046d512 --- /dev/null +++ b/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/ITokenManager.cs @@ -0,0 +1,27 @@ +using System.Threading; +using System.Threading.Tasks; +using System.Collections.Generic; + +namespace VNLib.Plugins.Essentials.Oauth.Tokens +{ + /// + /// Provides token creation and revocation + /// + public interface ITokenManager + { + /// + /// Revokes a colleciton of toke + /// + /// A collection of tokens to revoke + /// A token to cancel the operation + /// A task that completes when the tokens have been revoked + Task RevokeTokensAsync(IReadOnlyCollection tokens, CancellationToken cancellation = default); + /// + /// Attempts to revoke tokens that belong to a specified application + /// + /// The application to revoke tokens for + /// A token to cancel the operation + /// A task that completes when the work is complete + Task RevokeTokensForAppAsync(string appId, CancellationToken cancellation = default); + } +} \ No newline at end of file diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/TokenStore.cs b/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/TokenStore.cs new file mode 100644 index 0000000..56bb9f7 --- /dev/null +++ b/Libs/VNLib.Plugins.Essentials.Oauth/Tokens/TokenStore.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +using Microsoft.EntityFrameworkCore; + +using VNLib.Utils; +using VNLib.Plugins.Essentials.Oauth.Applications; + +namespace VNLib.Plugins.Essentials.Oauth.Tokens +{ + /// + /// Represents a database backed + /// that allows for communicating token information to + /// plugins + /// + public sealed class TokenStore : ITokenManager + { + private readonly DbContextOptions Options; + + /// + /// Initializes a new that will make quries against + /// the supplied + /// + /// The DB connection context + public TokenStore(DbContextOptions options) => Options = options; + + /// + /// 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 + /// + /// The token (or session id) + /// The applicaiton the token belongs to + /// The tokens refresh token + /// The maxium number of allowed tokens for a given application + /// A token to cancel the operation + /// + /// if the opreation succeeds (aka 0x01), + /// if the operation fails, or the number + /// of active tokens if the maximum has been reached. + /// + public async Task 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 + where t.ApplicationId == appId + select t) + .CountAsync(cancellation); + //Check count + if(count >= maxTokens) + { + return count; + } + + //Try to add the new token + ActiveToken newToken = new() + { + ApplicationId = appId, + Id = token, + RefreshToken = refreshToken, + Created = DateTime.UtcNow, + LastModified = DateTime.UtcNow + }; + //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; + } + + /// + /// Revokes/removes a single token from the store by its ID + /// + /// The token to remove + /// + /// A task that revolves when the token is removed from the table if it exists + 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) + { + return; + } + //delete token + ctx.OAuthTokens.Remove(at); + //Save changes + await ctx.SaveChangesAsync(cancellation); + await ctx.CommitTransactionAsync(cancellation); + } + /// + /// Removes all token entires that were created before the specified time + /// + /// The time before which all tokens are invaid + /// A token the cancel the operation + /// A task that resolves to a collection of tokens that were removed + public async Task> CleanupExpiredTokensAsync(DateTimeOffset 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 + select t) + .ToArrayAsync(cancellation); + + //delete token + ctx.OAuthTokens.RemoveRange(at); + //Save changes + int count = await ctx.SaveChangesAsync(cancellation); + await ctx.CommitTransactionAsync(cancellation); + return at; + } + /// + public async Task RevokeTokensAsync(IReadOnlyCollection 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) + select t) + .ToArrayAsync(cancellation); + + //delete token + ctx.OAuthTokens.RemoveRange(at); + //Save changes + await ctx.SaveChangesAsync(cancellation); + await ctx.CommitTransactionAsync(cancellation); + } + /// + 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 + select t) + .ToArrayAsync(cancellation); + //Set created time to 0 to invalidate the token + foreach(ActiveToken t in at) + { + //Expire token so next cleanup round will wipe tokens + t.Created = DateTime.MinValue; + } + //Save changes + await ctx.SaveChangesAsync(cancellation); + await ctx.CommitTransactionAsync(cancellation); + } + } +} diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/VNLib.Plugins.Essentials.Oauth.csproj b/Libs/VNLib.Plugins.Essentials.Oauth/VNLib.Plugins.Essentials.Oauth.csproj new file mode 100644 index 0000000..49c3c84 --- /dev/null +++ b/Libs/VNLib.Plugins.Essentials.Oauth/VNLib.Plugins.Essentials.Oauth.csproj @@ -0,0 +1,45 @@ + + + + net6.0 + AnyCPU;x64 + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + true + Vaughn Nugent + Copyright © 2022 Vaughn Nugent + www.vaughnnugent.com/resources + 1.0.2.1 + enable + True + + + + + + + + + + + diff --git a/Libs/VNLib.Plugins.Essentials.Oauth/VNLib.Plugins.Essentials.Oauth.xml b/Libs/VNLib.Plugins.Essentials.Oauth/VNLib.Plugins.Essentials.Oauth.xml new file mode 100644 index 0000000..ad8e968 --- /dev/null +++ b/Libs/VNLib.Plugins.Essentials.Oauth/VNLib.Plugins.Essentials.Oauth.xml @@ -0,0 +1,155 @@ + + + + VNLib.Plugins.Essentials.Oauth + + + + + A DbStore for s for OAuth2 client applications + + + + + Initializes a new data store + uisng the specified EFCore object. + + EFCore context options for connecting to a remote data-store + A structure for hashing client secrets + The name of the applications table + The name of the active OAuth2 token table + + + + Updates the secret of an application, and if successful returns the new raw secret data + + The user-id of that owns the application + The id of the application to update + A task that resolves to the raw secret that was used to generate the hash, or null if the operation failed + + + + Attempts to retreive an application by the specified client id and compares the raw secret against the + stored secret hash. + + The clientid of the application to search + The secret to compare against + The found application + True if the application was found and the secret matches the stored secret, false if the appliation was not found or the secret does not match + + + + Deletes all active tokens + + + + + + Generates a client application secret using the library + + The RNG secret + + + + Creates and initializes a new with a random clientid and + secret that must be disposed + + The new record to create + The result of the operation + + + + Generates a new client ID using the library + + The new client ID + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Provides a one-time-use handle (similar to asyncReleaser, or openHandle) + that holds exclusive access to a session until it is released + + + + + Provides OAuth2 sessions (with caching) using VNLib caching store + + + + + Initializes a new + + The a factory function + The name of the table that the backing store indexes + The maximum number of sessions to keep in memory + A secure access token factory function + + + + Asynchronously gets the number of active tokens for a given application + + The application id to get the count of + A task that resolves the number of active tokens + + + + Gets a session handle for the current token to attach to a connection + + The access token (or session id) to get the session of + A token to cancel the operation + A task the resolves a around the session to connect to the token and entity + + + + + + Creates a new OAuth2 session in the store and returns a handle to the new session + + The application id + The IP address of the client that created the token + A token to cancel the operation + A task that compeltes with an used to release the session + + + + + A value that indicates if the session has been released, returns false if the instance has not been initialized + + + + + Waits for exclusive access to the resource and lazily initializes the resource + from its backing store + + Optional ipaddressfor initalization + A token to cancel the operation + A task the resolves to a value that indicates if the session is in a usable state + + + -- cgit