Pargoon.Core.JWT 1.0.0

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.
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.
// Install Pargoon.Core.JWT as a Cake Addin
#addin nuget:?package=Pargoon.Core.JWT&version=1.0.0

// Install Pargoon.Core.JWT as a Cake Tool
#tool nuget:?package=Pargoon.Core.JWT&version=1.0.0

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. 
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 109 4/21/2024

Adding JwtConfig and JwtSettings