Auth.JWT 2.1.0

dotnet add package Auth.JWT --version 2.1.0
NuGet\Install-Package Auth.JWT -Version 2.1.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="Auth.JWT" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Auth.JWT --version 2.1.0
#r "nuget: Auth.JWT, 2.1.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 Auth.JWT as a Cake Addin
#addin nuget:?package=Auth.JWT&version=2.1.0

// Install Auth.JWT as a Cake Tool
#tool nuget:?package=Auth.JWT&version=2.1.0

Nuget Details

dotnet add package Auth.JWT

https://www.nuget.org/packages/Auth.JWT/

Auth JWT

What is JWT (Json Web Token)?

JSON Web Token (JWT) is a token based authentication between two servers. In this a JSON object that

is digitally signed using JSON Web Signature (JWS) and encrypted using JSON Web Encryption (JWE).

Authentication sequence for JWT

What is Auth JWT?

Auth JWT is a helper to achieve JWT authentication in ASP.Net Core applications in an easy and flexible

way.

Hashing Algorithms Used

➢ SHA1

➢ SHA256

➢ SHA384

➢ SHA512

Components of Auth JWT

➢ TokenRequestModel is a class which contain properties for Auth JWT payload.

o [Note: All properties are not mandatory.]

Issuer

ExpiryInSeconds

UserId

User

Role

Audience

JwtId

Subject

CustomProperty

AlgorithmType is constant class to get the algorithm details

SHA1

SHA256

SHA384

SHA512

JWTModule is a class which contains all the interfaces for Auth JWT.

CreateToken(<TokenRequestModel>, <secrect>, <AlgoritmType>) → Function creates

the token

VerifyToken(<token>, <secrect>, <ValidateModel Optional>) → Function verifies

the token.

TokenResponseModel is a class which contains the Status and Content of the Auth

JWT response.

Status

Content

ValidateModel is a class which contain properties to be verified in the

VerifyToken() function.

o

[Note: All properties should match the TokenRequestModel.]

Issuer

UserId

User

Role

Audience

JwtId

Subject

CustomProperty

Configuration of Auth.JWT

Step 1:

Add the service to the ConfigureServices(IServiceCollection services) function.

services.AddAuthService();

Step 3

Implement Constructor injection in the required classes, to get the object of Auth.JWT.

Sample Code Snippet

In the below code, I have used Auth.JWT to create and validate the token in a simple class for better

understanding.

class TestAuthJwt

{

private readonly JWTModule _module;

private readonly TokenRequestModel _reqModel;

private readonly ValidateModel _validateModel;

public TestAuthJwt(JWTModule module, TokenRequestModel reqModel, ValidateModel

validateModel)

{

_module = module;

_reqModel = reqModel;

_validateModel = validateModel;

}

public void Execute()

{

string secrect = "F4760D";

_reqModel.Issuer = "authjwt_team";

_reqModel.ExpiryInSeconds = "1000";

_reqModel.UserId = "U1324322";

_reqModel.User = "sambeet";

_reqModel.Role = "admin";

_reqModel.Audience = "authjwt_app";

_reqModel.JwtId = "J4433421";

_reqModel.Subject = "authjwt_subject";

_reqModel.CustomProperty.Add("CustomField1","auth_custom1");

_reqModel.CustomProperty.Add("CustomField2", "auth_custom2");

var result = _module.CreateToken(_reqModel, secrect, AlgorithmType.SHA256);

Console.WriteLine("************* Create Token Result***************");

Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(result));

_validateModel.Issuer = "authjwt_team";

_validateModel.UserId = "U1324322";

_validateModel.User = "sambeet";

_validateModel.Role = "admin";

_validateModel.Audience = "authjwt_app";

_validateModel.JwtId = "J4433421";

_validateModel.Subject = "authjwt_subject";

_validateModel.CustomProperty.Add("CustomField1", "auth_custom1");

_validateModel.CustomProperty.Add("CustomField2", "auth_custom2");

var verifyResult = _module.VerifyToken(result.Content, secrect, _validateModel);

Console.WriteLine("************* Verify Token Result***************");

Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(verifyResult));

Console.ReadKey();

}

}

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
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
2.1.0 95 3/3/2024
2.0.0 261 1/24/2023
1.0.9 1,284 4/2/2022
1.0.8 422 7/18/2021
1.0.7 503 7/18/2020
1.0.6 414 7/6/2020
1.0.5 622 4/17/2019
1.0.4 548 4/5/2019
1.0.3 534 4/5/2019
1.0.2 562 4/2/2019
1.0.1 544 4/2/2019
1.0.0 540 4/1/2019

Following is the user manual:
-------------------------------------
https://1drv.ms/b/s!AhdXGbbVEmBIhAkDCzDoqnpuWdvP?e=7SdFq8