Pargoon.Core.JWT
1.0.0
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
<PackageReference Include="Pargoon.Core.JWT" Version="1.0.0" />
paket add Pargoon.Core.JWT --version 1.0.0
#r "nuget: Pargoon.Core.JWT, 1.0.0"
// 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 | Versions 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. |
-
net8.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.4)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.IdentityModel.Tokens (>= 7.5.1)
- System.IdentityModel.Tokens.Jwt (>= 7.5.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Adding JwtConfig and JwtSettings