Jwt_Authentication 1.0.0

dotnet add package Jwt_Authentication --version 1.0.0
                    
NuGet\Install-Package Jwt_Authentication -Version 1.0.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="Jwt_Authentication" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Jwt_Authentication" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Jwt_Authentication" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Jwt_Authentication --version 1.0.0
                    
#r "nuget: Jwt_Authentication, 1.0.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.
#:package Jwt_Authentication@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Jwt_Authentication&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Jwt_Authentication&version=1.0.0
                    
Install as a Cake Tool

GenerateToken

Generates a JWT token for the provided application user.

Parameters

  1. T applicationUser: The user for whom the token is being generated. This can be any type that represents your application user.

  2. double ExpMinute: The expiration time of the token in minutes.

  3. JwtOptions: Configuration options for generating the JWT token.

    The JwtOptions class should include the following properties:
     string Issuer: The issuer of the token.
     string Audience: The audience for the token.
     string SigningKey: The key used to sign the token.
    

Returns

string: The generated JWT token.

GetTokenInfo

Retrieves information from a given JWT token.

Parameters

string token: The JWT token from which to retrieve information.

Returns

Dictionary<string, string>: A dictionary containing the token's claims and their values.

ValidateToken

Validates the provided JWT token against the given options.

Parameters

string authToken: The JWT token to validate. JwtOptions: Configuration options for validating the JWT token.

Returns

bool: true if the token is valid, otherwise false.

Examples:

public class JwtOptions { public string Issuer { get; set; } public string Audience { get; set; } public string SigningKey { get; set; } }

Here is a basic example of how to use the library:

public class Program { public static void Main(string[] args) { var user = new { Id = 1, Username = "user1" }; // Example user object var jwtOptions = new JwtOptions { Issuer = "YourIssuer", Audience = "YourAudience", SigningKey = "YourSigningKey" };

    // Generate Token
    string token = TokenUtility.GenerateToken(user, 60, jwtOptions);
    Console.WriteLine($"Generated Token: {token}");

    // Get Token Info
    var tokenInfo = TokenUtility.GetTokenInfo(token);
    foreach (var info in tokenInfo)
    {
        Console.WriteLine($"{info.Key}: {info.Value}");
    }

    // Validate Token
    bool isValid = TokenUtility.ValidateToken(token, jwtOptions);
    Console.WriteLine($"Is Token Valid: {isValid}");
}

}

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
1.0.0 136 5/28/2024