Token.Generator.JWT.Login 1.0.1

dotnet add package Token.Generator.JWT.Login --version 1.0.1
NuGet\Install-Package Token.Generator.JWT.Login -Version 1.0.1
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="Token.Generator.JWT.Login" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Token.Generator.JWT.Login --version 1.0.1
#r "nuget: Token.Generator.JWT.Login, 1.0.1"
#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 Token.Generator.JWT.Login as a Cake Addin
#addin nuget:?package=Token.Generator.JWT.Login&version=1.0.1

// Install Token.Generator.JWT.Login as a Cake Tool
#tool nuget:?package=Token.Generator.JWT.Login&version=1.0.1

Español

Sobre Token.Generator.JWT.Login Nuget Package

Token Generator JWT es un componente que sirve para generar tokens de tipo JWT y realizar de forma más fácil y rápida aplicaciones seguras con .Net Core.

Modo de uso y/o empleo

image

  1. Ingresar al Nuget de Visual Studio y escribir en el buscador de paquetes NUGET <Token.Generator.JWT.Login

  2. Installar el paquete

  3. Emplear el código de desarrollo

Ejemplo de código en uso (Minimal API .Net Core 6) - appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "JWT": {
    "ServerSecret": "qwertyuiopasdfghjklzxcvbnm123456",
    "Issuer": "http://10.2.1.99:35",
    "Audience": "http://10.2.1.99:35"
  }
}

Ejemplo de código en uso (Minimal API .Net Core 6) - Program.cs

using Microsoft.AspNetCore.Mvc;
using Token.Generator.JWT.Login;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddSingleton<TokenService>(new TokenService()); // Agregar el servicio del Token

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

var summaries = new[]
{
    "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

//Token Generator example
app.MapPost("login", async ([FromBodyAttribute] UserLogin userModel, TokenService tokenService) =>
{

    userModel.UserName = "abieljesrrel";

    var token = tokenService.BuildToken(builder.Configuration["Jwt:ServerSecret"], builder.Configuration["Jwt:Issuer"], builder.Configuration["Jwt:Audience"], userModel.UserName);

    return token;
});

app.MapGet("/weatherforecast", () =>
{
    var forecast = Enumerable.Range(1, 5).Select(index =>
        new WeatherForecast
        (
            DateTime.Now.AddDays(index),
            Random.Shared.Next(-20, 55),
            summaries[Random.Shared.Next(summaries.Length)]
        ))
        .ToArray();
    return forecast;
})
.WithName("GetWeatherForecast");

app.Run();

internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary)
{
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}

record UserLogin
{
    public string UserName { get; set; }
    public string Password { get; set; }
}

Respuesta desde Swagger

image

English

About Token.Generator.JWT.Login Nuget Package

JWT Token Generator is a component used to generate JWT type tokens and make secure applications with .Net Core easier and faster.

Mode of use and/or employment

image

  1. Enter the Visual Studio Nuget and write in the package browser NUGET <Token.Generator.JWT.Login

  2. Install the package

  3. Employ development code

Code example in use (Minimal API .Net Core 6) - appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "JWT": {
    "ServerSecret": "qwertyuiopasdfghjklzxcvbnm123456", //Generate your Bearer secret token
    "Issuer": "http://10.2.1.99:35", //Your Issuer URL
    "Audience": "http://10.2.1.99:35" //Yur Audience URL
  }
}

Example code in use (Minimal API .Net Core 6) - Program.cs

using Microsoft.AspNetCore.Mvc;
using Token.Generator.JWT.Login;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddSingleton<TokenService>(new TokenService()); // Agregar el servicio del Token

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

var summaries = new[]
{
    "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

//Token Generator example
app.MapPost("login", async ([FromBodyAttribute] UserLogin userModel, TokenService tokenService) =>
{

    userModel.UserName = "abieljesrrel";

    var token = tokenService.BuildToken(builder.Configuration["Jwt:ServerSecret"], builder.Configuration["Jwt:Issuer"], builder.Configuration["Jwt:Audience"], userModel.UserName);

    return token;
});

app.MapGet("/weatherforecast", () =>
{
    var forecast = Enumerable.Range(1, 5).Select(index =>
        new WeatherForecast
        (
            DateTime.Now.AddDays(index),
            Random.Shared.Next(-20, 55),
            summaries[Random.Shared.Next(summaries.Length)]
        ))
        .ToArray();
    return forecast;
})
.WithName("GetWeatherForecast");

app.Run();

internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary)
{
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}

record UserLogin
{
    public string UserName { get; set; }
    public string Password { get; set; }
}

Reply from Swagger

image

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. 
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.1 410 6/16/2022
1.0.0 377 6/14/2022

Se optimizo la generación del token y se agrego cadusidad de token único por usuario.

Para saber como implementar el paquete, vivitar esta página: https://github.com/wecreativedigital/Token.Generator.JWT.Login

¿Fué de utilidad el paquete para ti?
Regálame una tasa de cafe a mi cuenta de Paypal: jesrrel1989.1989@gmail.com

¿Deseas más paquetes?
Hazmelo saber a mi correo jesrrel1989.1989@gmail.com

Gracias a tod@s!