CoreJsonWebToken 2025.7.13

dotnet add package CoreJsonWebToken --version 2025.7.13
                    
NuGet\Install-Package CoreJsonWebToken -Version 2025.7.13
                    
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="CoreJsonWebToken" Version="2025.7.13" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreJsonWebToken" Version="2025.7.13" />
                    
Directory.Packages.props
<PackageReference Include="CoreJsonWebToken" />
                    
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 CoreJsonWebToken --version 2025.7.13
                    
#r "nuget: CoreJsonWebToken, 2025.7.13"
                    
#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 CoreJsonWebToken@2025.7.13
                    
#: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=CoreJsonWebToken&version=2025.7.13
                    
Install as a Cake Addin
#tool nuget:?package=CoreJsonWebToken&version=2025.7.13
                    
Install as a Cake Tool

DotNet.CoreAuthorizationJwt

Biblioteca que facilita la implementación de autenticación JWT en aplicaciones ASP.NET Core.

Características

  • Generación de tokens JWT segura
  • Configuración flexible
  • Manejo de claves de seguridad
  • Validación de tokens
  • Soporte para múltiples audiencias
  • Configuración de expiración
  • Inyección de dependencias

Instalación

El componente se puede instalar como un paquete NuGet:

dotnet add package DeveloperKit.CoreAuthorizationJwt

Requisitos

  • .NET Core 3.1 o superior
  • ASP.NET Core
  • Visual Studio 2019 o superior

Configuración

Configuración Básica

public void ConfigureServices(IServiceCollection services)
{
    services.AddJsonWebToken(options =>
    {
        options.SecurityKey = "your-secret-key-here";
        options.ValidIssuer = "your-domain.com";
        options.ValidAudience = "your-client-id";
        options.ExpireInMinutes = 60;
    });
}

Configuración Avanzada

public void ConfigureServices(IServiceCollection services)
{
    services.AddJsonWebToken(options =>
    {
        // Clave de seguridad (mínimo 16 caracteres)
        options.SecurityKey = "your-very-long-secret-key-here";
        
        // Emisor del token
        options.ValidIssuer = "https://api.yourdomain.com";
        
        // Cliente que puede usar el token
        options.ValidAudience = "client-123";
        
        // Duración del token en minutos
        options.ExpireInMinutes = 120;
    }, ServiceLifetime.Scoped);
}

Uso

Generación de Token

public class TokenService
{
    private readonly IAccessToken _accessToken;

    public TokenService(IAccessToken accessToken)
    {
        _accessToken = accessToken;
    }

    public async Task<string> GenerateTokenAsync(string userId, string role)
    {
        return await _accessToken.GetTokenAsync(configurations =>
        {
            configurations.Add("userId", userId);
            configurations.Add("role", role);
        });
    }
}

Validación de Token

[Authorize]
public class ProtectedController : ControllerBase
{
    [HttpGet]
    public IActionResult GetProtectedData()
    {
        // El token se valida automáticamente por el middleware de autenticación
        return Ok(new { data = "Protected data" });
    }
}

Configuración de Middleware

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // ... otras configuraciones

    app.UseAuthentication();
    app.UseAuthorization();

    // ... otras configuraciones
}

Mejores Prácticas

  1. Seguridad

    • Usar claves de seguridad largas y complejas
    • No usar la misma clave de seguridad en múltiples entornos
    • Rotar las claves de seguridad periódicamente
    • Usar HTTPS para todas las comunicaciones
  2. Configuración

    • Almacenar claves de seguridad en variables de entorno
    • Usar diferentes configuraciones por entorno
    • Validar la configuración en el inicio de la aplicación
  3. Manejo de Tokens

    • Implementar refrescos de token
    • Manejar tokens expirados
    • Validar firmas de token
    • Usar claims apropiados
  4. Rendimiento

    • Usar caché para tokens frecuentes
    • Implementar limitación de velocidad
    • Manejar eficientemente la memoria

Soporte

Para reportar errores o solicitar características, por favor abre un issue en el repositorio de GitHub.

Licencia

Este proyecto está bajo licencia MIT. Consulta el archivo LICENSE para más detalles.

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 is compatible.  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
2025.7.13 144 7/14/2025
2025.5.23 104 5/23/2025
2025.5.1 155 5/1/2025
2025.4.30 144 4/30/2025
2025.4.16 198 4/17/2025
2025.4.14 221 4/15/2025
2025.4.9 169 4/9/2025
2025.4.8 152 4/8/2025
2025.4.7 150 4/8/2025
2025.3.22 162 3/22/2025
2025.3.8 130 3/9/2025
2025.2.1 137 2/1/2025
2024.11.12 133 11/12/2024
2024.10.6 115 10/4/2024
2024.9.29 124 9/28/2024
2024.9.28 115 9/28/2024
2024.9.3 138 9/4/2024