| Package Name | Version | Downloads |
|---|---|---|
| Revoke.NET | ||
| Revoke.NET.AspNetCore | ||
| Revoke.NET.Akavache | ||
| Revoke.NET.MongoDB | ||
| Revoke.NET.Redis | ||
| Revoke.NET.EasyCaching |
.NET Utility to revoke access based on some given criterias including but not limited to:
- Web Tokens like JWT Bearer token
- HTTP Request Header Paramters, Query, URL, Host, IP, Cookies, Body, FormData, Claims...etc
First, install the Revoke.NET into your app
Install-Package Revoke.NETor with dotnet cli:
dotnet add package Revoke.NETsimple create a new BlackList Store of type IBlackListStore
usingRevoke.NET;varstore=MemoryBlackListStore.CreateStore();// Create a blacklist store, core package come with non-persistent in-memory storevarkey="[ID String of something to be blacklisted]";awaitstore.Revoke(key,TimeSpan.FromHours(24));// Revoke access to a key for 24 hoursawaitstore.Revoke(key);// Revoke access indefinetly or with the defaulTtl expirationvarrevoked=awaitstore.IsRevoked(key);// Check if key is blacklistedawaitstore.Delete(key);// Delete a key from blacklistInstall the Revoke.NET.AspNetCore into your app
Install-Package Revoke.NET.AspNetCoreor with dotnet cli:
dotnet add package Revoke.NET.AspNetCoreusingRevoke.NET;varbuilder=WebApplication.CreateBuilder(args);builder.Services.AddRevokeStore(()=>/* provide a BlackList Store */).AddHttpContextRevokeMiddleware(
context =>{/* create custom key selector from HttpContext */},
response =>{/* create a custom response to be sent when a request is revoked */});usingSystem.Net.Http.Headers;usingMicrosoft.AspNetCore.Mvc;usingRevoke.NET;varbuilder=WebApplication.CreateBuilder(args);builder.Services.AddRevokeInMemoryStore()// Register a Revoke Store.AddJWTBearerTokenRevokeMiddleware();// Register a Revoke Middlewarevarapp=builder.Build();app.UseRevoke();// Use Middleware before calling UseAuthorization()app.UseAuthorization();app.UseAuthentication();app.MapGet("/logout",async([FromServices]IBlackListStorestore,HttpRequestrequest)=>{vartoken=AuthenticationHeaderValue.Parse(request.Headers.Authorization).Parameter;awaitstore.Revoke(token);returntrue;});app.Run();