Jwt_Authentication 1.0.0
dotnet add package Jwt_Authentication --version 1.0.0
NuGet\Install-Package Jwt_Authentication -Version 1.0.0
<PackageReference Include="Jwt_Authentication" Version="1.0.0" />
<PackageVersion Include="Jwt_Authentication" Version="1.0.0" />
<PackageReference Include="Jwt_Authentication" />
paket add Jwt_Authentication --version 1.0.0
#r "nuget: Jwt_Authentication, 1.0.0"
#:package Jwt_Authentication@1.0.0
#addin nuget:?package=Jwt_Authentication&version=1.0.0
#tool nuget:?package=Jwt_Authentication&version=1.0.0
GenerateToken
Generates a JWT token for the provided application user.
Parameters
T applicationUser: The user for whom the token is being generated. This can be any type that represents your application user.
double ExpMinute: The expiration time of the token in minutes.
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 | Versions 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. |
-
net6.0
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 |