Red.JwtSessions
1.1.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Red.JwtSessions --version 1.1.1
NuGet\Install-Package Red.JwtSessions -Version 1.1.1
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.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Red.JwtSessions --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Red.JwtSessions, 1.1.1"
#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.1.1 // Install Red.JwtSessions as a Cake Tool #tool nuget:?package=Red.JwtSessions&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Jwt Sessions for RedHttpServer
Simple session management middleware for Red using JWT.Net
Usage
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..." }'
Example
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"});
}
else
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 | Versions 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.
-
.NETCoreApp 2.0
- JWT (>= 4.0.0)
- RHttpServer (>= 3.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
changed the way to determine whether a path requires authentication. Now using Func<string,bool>