Skip to content

Repository files navigation

Package NameVersionDownloads
Revoke.NETLatest versionDownloads
Revoke.NET.AspNetCoreLatest versionDownloads
Revoke.NET.AkavacheLatest versionDownloads
Revoke.NET.MongoDBLatest versionDownloads
Revoke.NET.RedisLatest versionDownloads
Revoke.NET.EasyCachingLatest versionDownloads

Revoke.NET

.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

Installation

First, install the Revoke.NET into your app

Install-Package Revoke.NET

or with dotnet cli:

dotnet add package Revoke.NET

How to use

simple 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 blacklist

Usage with ASP.NET Core

Install the Revoke.NET.AspNetCore into your app

Install-Package Revoke.NET.AspNetCore

or with dotnet cli:

dotnet add package Revoke.NET.AspNetCore
usingRevoke.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 */});

JWT Bearer Token Example

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();

About

.NET Utility to blacklist & revoke access to stuff

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages