TrivialJwt 0.3.0
See the version list below for details.
dotnet add package TrivialJwt --version 0.3.0
NuGet\Install-Package TrivialJwt -Version 0.3.0
<PackageReference Include="TrivialJwt" Version="0.3.0" />
paket add TrivialJwt --version 0.3.0
#r "nuget: TrivialJwt, 0.3.0"
// Install TrivialJwt as a Cake Addin #addin nuget:?package=TrivialJwt&version=0.3.0 // Install TrivialJwt as a Cake Tool #tool nuget:?package=TrivialJwt&version=0.3.0
TrivialJWT
TrivialJWT is a set of libraries to ease:
- The creation of JWT tokens
- The validation of JWT tokens
TrivialJWT
exposes an end point to generate JWT token.
It relies on Microsoft's libraries for JWT generation.
TrivialJWT.Bearer
helps configure the Microsoft.AspNetCore.Authentication.JwtBearer
library based on TrivialJWT
configuration.
TrivialJWT.AspNetIdentity
implements the required interfaces to bridge TrivialJWT
with Microsoft.AspNetCore.Identity
.
2 samples are provided:
How to use TrivialJWT
with AspNetIdentity
Install dependencies
With .NET CLI
dotnet add package TrivialJwt.Bearer
dotnet add package TrivialJwt.AspNetIdentity
or with Package Manager:
Install-Package TrivialJwt.Bearer
Install-Package TrivialJwt.AspNetIdentity
Update Startup.cs
In the example below, a HMAC-SHA265 signature
(...)
using TrivialJwt;
using TrivialJwt.AspNetIdentity;
using TrivialJwt.Bearer;
(...)
public void ConfigureServices(IServiceCollection services)
{
(...)
services.AddTrivialJwtAspNetIdentity<AppUser>(options =>
{
options.Secret = "<Base64Secret>"
});
services.AddTrivialJwtAuthentication();
(...)
}
public void Configure(IApplicationBuilder app,
IWebHostEnvironment env)
{
(...)
app.UseAuthentication();
app.UseAuthorization();
(...)
}
How to use TrivialJWT
without AspNetIdentity
Install dependencies
With .NET CLI
dotnet add package TrivialJwt.Bearer
or with Package Manager:
Install-Package TrivialJwt.Bearer
Update Startup.cs
In the example below, a HMAC-SHA265 signature
(...)
using TrivialJwt;
using TrivialJwt.Bearer;
(...)
public void ConfigureServices(IServiceCollection services)
{
(...)
services.AddTrivialJwt(options =>
{
options.Secret = "<Base64Secret>"
});
services.AddTrivialJwtAuthentication();
services.AddScoped<IPasswordValidator, PasswordValidator>();
services.AddScoped<IClaimsIdentityProvider, ClaimsIdentityProvider>();
(...)
}
public void Configure(IApplicationBuilder app,
IWebHostEnvironment env)
{
(...)
app.UseAuthentication();
app.UseAuthorization();
(...)
}
An implementation for IPasswordValidator
and IClaimsIdentityProvider
must be provided.
Configuration
Configuration can be done by using options as shown above or by binding:
services.AddTrivialJwtAspNetIdentity<IdentityUser>(
Configuration.GetSection(TrivialJwtOptions.Section));
For instance, the appsettings.json
can contain the configuration:
{
"TrivialJwt": {
"Secret": "U3VwZXJfU2VjcmV0X1Bhc3N3b3JkIQ=="
}
}
Endpoints
Token generation endpoint
The endpoint is /auth/login
.
The payload is a JSON with username
and password
.
Example:
{
"username": "bob",
"password": "bob"
}
The response would be:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdW...k_Riw4RSK7g",
"refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdW...k_Riw4RSK7g",
"expires_in": 3600,
"token_type": "bearer"
}
Refresh token endpoint
The endpoint is /auth/refresh_token
.
The payload is a JSON file with refresh_token
.
Example:
{
"refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdW...k_Riw4RSK7g"
}
The response would be:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdW...k_Riw4RSK7g",
"refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdW...k_Riw4RSK7g",
"expires_in": 3600,
"token_type": "bearer"
}
Refresh Token endpoint
The endpoint is /auth/refreshtoken
.
The payload is a JSON file with username
and password
.
Example:
{
"username": "bob",
"password": "bob"
}
TODO
- support .Net 5.0
- Implement elliptic curves
- Enhance asymmetric key management
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 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.AspNetCore.Mvc.Formatters.Json (>= 2.2.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
- Microsoft.IdentityModel.Tokens (>= 6.8.0)
- System.ComponentModel.Annotations (>= 5.0.0)
- System.IdentityModel.Tokens.Jwt (>= 6.8.0)
- System.Text.Json (>= 5.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on TrivialJwt:
Package | Downloads |
---|---|
TrivialJwt.Bearer
A Trivial package to configure token validation generated by TrivialJwt |
|
TrivialJwt.AspNetIdentity
A Trivial package to generate token based on AspNetIdentity |
GitHub repositories
This package is not used by any popular GitHub repositories.