Red.JwtSessions 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Red.JwtSessions --version 1.2.0                
NuGet\Install-Package Red.JwtSessions -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Red.JwtSessions" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Red.JwtSessions --version 1.2.0                
#r "nuget: Red.JwtSessions, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Red.JwtSessions as a Cake Addin
#addin nuget:?package=Red.JwtSessions&version=1.2.0

// Install Red.JwtSessions as a Cake Tool
#tool nuget:?package=Red.JwtSessions&version=1.2.0                

Jwt Sessions for RedHttpServer

Simple session management middleware for Red using JWT.Net


After installing and referencing this library, the Red.Response has the extension method SendJwtToken(sessionData).

'SendJwtToken(sessionData)' creates a new Jwt token using the provided session-data and sends it JSON encoded: '{ "JWT": "Bearer eyJ0eXAiOiJKV1QiL..." }'


class MySession 
    public string Username;
server.Use(new JwtSessions<MySession>(new JwtSessionSettings(TimeSpan.FromDays(1), "my secret secret")
    ShouldAuthenticate = path => path != "/login" // We allow people to send requests without a valid Authorization to /login, where we can authenticate them

server.Get("/login", async (req, res) =>
    var form = await res.GetFormDataAsync();
    if (ValidForm(form) && Authenticate(form["username"], form["password"]))
        await res.SendJwtToken(new MySession {Username = "benny"});
        await res.SendStatus(HttpStatusCode.BadRequest);

// Only authenticated users are allowed to /friends
server.Get("/friends", async (req, res) => 
    var session = req.GetData<MySession>();
    var friends = database.GetFriendsOfUser(session.Username);
    await res.SendJson(friends);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 1,691 4/30/2019
2.1.0 1,669 9/12/2018
2.0.0 1,790 6/26/2018
1.2.0 1,755 5/20/2018
1.1.1 1,681 5/19/2018
1.1.0 1,728 5/19/2018
1.0.0 1,895 4/20/2018

changed the way of handling denied requests, so it can be customized