Pargoon.Core.JWT 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pargoon.Core.JWT --version 1.0.0
                    
NuGet\Install-Package Pargoon.Core.JWT -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="Pargoon.Core.JWT" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pargoon.Core.JWT" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Pargoon.Core.JWT" />
                    
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 Pargoon.Core.JWT --version 1.0.0
                    
#r "nuget: Pargoon.Core.JWT, 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 Pargoon.Core.JWT@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=Pargoon.Core.JWT&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Pargoon.Core.JWT&version=1.0.0
                    
Install as a Cake Tool

Pargoon.Core.JWT

you can use JwtSettings as a model for reading jwt settings from appSettings.json and also you can configure jwt with JwtConfig.ConfigureJwt() method in Program.cs this method read JwtSettings with IOptions pattern from appSettings.json and configure jwt for app

this a sample for using it : first add this section to the appsettings.json

  "JwtSettings": {
    "Secret": "F@*&SDmJiD6!0%0okenspodp4543543iksdfsdfi6%0!#%*FGD&(¨ABC(&VY&(6dfsutf7f6dod8g-f&TG08tdt&sfgssxxsaaaa&astdecatechlabs",
    "EncKey": "1234KeyEncryptKeyEncryptKeyEncryptKey&(SFGD&(¨SFD(&VY&(6dfsutf7f6dod8g-f&TG08ttsdt&sfgd&astdecatechlabs",
    "Issuer": "https://myWebSiteAddress.com",
    "Audience": "myAudienceName"
  }

then add these code to Program.cs to configure jwt

// in program.cs
builder.Services.Configure<JwtSettings>(builder.Configuration.GetSection(JwtSettings.SectionName));
builder.Services.ConfigureJwt();

this is a sample for adding login endpoint for creating a jwt token

using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Pargoon.Core;

namespace Ava.ShahkarClient.Api.Controllers.v1;

[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")]
[ApiController]
public class AccountController : ControllerBase
{
	private readonly IAccountService _account;
	private readonly JwtSetting _jwtSetting;

	public ShahkarController(IAccountService account, IOptions<JwtSetting> jwtOptions)
	{
		_account = account;
		_jwtSetting = jwtOptions.Value;
	}

	[HttpPost("Login")]
	[ProducesResponseType(typeof(TResult<string>), 200)]
	[ProducesResponseType(typeof(Result), 401)]
	public async Task<IActionResult> LoginAsync(UserLoginRequest model)
	{
		var result = await _account.UserLoginAsync(model);
		if (result != null)
		{			
			string token = JwtConfig.CreateToken(model.Username, result.UniqueId, result.RoleNamesOrIds, _jwtSetting);
			return Ok(new TResult<string>("login successfull", token));
		}
		return Unauthorized(new UnauthorizedDataResult("login failed"));
	}
}
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.  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
9.0.0 251 11/16/2024
8.0.4 285 10/9/2024
8.0.3 849 8/20/2024
8.0.2 194 8/17/2024
8.0.1 164 8/3/2024
1.0.0 349 4/21/2024

Adding JwtConfig and JwtSettings