Bat.AspNetCore 8.0.1

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

// Install Bat.AspNetCore as a Cake Tool
#tool nuget:?package=Bat.AspNetCore&version=8.0.1                

For use Bat.AspNetCore just do it :

1- Install Bat.AspNetCore on your project

2- Use it in your project for example :

// Configure the Services.
builder.Services.AddBatAuthentication();

builder.Services.AddBatJwtConfiguration(_jwtSettings);

builder.Services.AddMemoryCache();

builder.Services.Configure<JwtSettings>(_configuration.GetSection("JwtSetting"));
builder.Services.AddTransient<IJwtService, JwtService>();

builder.Services.AddBatSwagger(_swaggerSetting);


// Configure the HTTP request pipeline.
app.UseMiddleware<BatJwtParserMiddleware>();

app.UseMiddleware<BatEnableRequestBufferingMiddleware>();

app.UseMiddleware<BatExceptionHandlingMiddleware>();

app.UseBatJwtConfiguration();

OR

public class JwtParserMiddleware
{
    private readonly RequestDelegate _next;
    private readonly IJwtService _jwtService;
    private readonly JwtSettings _jwtSettings;

    public JwtParserMiddleware(RequestDelegate next, IJwtService jwtService, IOptions<JwtSettings> jwtSettings)
    {
        _next = next;
        _jwtService = jwtService;
        _jwtSettings = jwtSettings.Value;
    }

    public async Task Invoke(HttpContext context)
    {
        var token = context.Request.Headers["Authorization"].FirstOrDefault()?.Split(" ").Last();
        try
        {
            if (token != null)
            {
                var userClaims = _jwtService.GetClaimsPrincipal(token, _jwtSettings);
                if (userClaims != null) context.User = userClaims;
            }
            else
            {
                if (context.User.Claims.Any())
                {
                    context.Response.StatusCode = (int)System.Net.HttpStatusCode.Unauthorized;
                    context.Response.ContentType = "application/Json";
                    var bytes = Encoding.ASCII.GetBytes(new { isSuccess = false, message = "UnAuthorized Access To Api !. Token Not Sent.", resultCode = 401 }.SerializeToJson());
                    await context.Response.Body.WriteAsync(bytes);
                }
            }

            await _next(context);
        }
        catch (Exception e)
        {
            byte[] bytes;
            if (e.Message.Contains("Lifetime validation failed"))
            {
                #region Expired Token
                //var validationTime = _jwtService.GetTokenExpireTime(token, _jwtSettings);
                bytes = Encoding.UTF8.GetBytes(new 
                {
                    resultCode = 1001,
                    isSuccess = false,
                    message = "JWT Token Lifetime has Expired. Please Login again!",
                }.SerializeToJson());
                #endregion
            }
            else
            {
                #region Another Exception
                bytes = Encoding.UTF8.GetBytes(new 
                {
                    resultCode = 1002,
                    isSuccess = false,
                    message = "Invalid JWT Token signature. Please refresh your token." +
                    Environment.NewLine + e.Message
                }.SerializeToJson());
                #endregion
            }

            context.Response.StatusCode = (int)System.Net.HttpStatusCode.Unauthorized;
            context.Response.ContentType = "application/Json";
            await context.Response.Body.WriteAsync(bytes);
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 is compatible.  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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
8.0.1 171 1/22/2024
8.0.0 215 12/1/2023
7.0.3 326 3/1/2023
7.0.2 307 2/4/2023
7.0.0 367 12/6/2022
6.0.22 199 8/19/2023
6.0.21 161 8/19/2023
6.0.1 689 3/27/2022
1.1.6 447 12/26/2021
1.1.5 589 7/12/2021
1.1.4 521 4/8/2021
1.1.3 462 4/8/2021
1.1.2 460 4/3/2021
1.1.1 506 4/3/2021
1.1.0 483 3/26/2021
1.0.7 448 2/4/2021
1.0.4 611 10/19/2020

- Upgrade to Net8.0 and C#12.0
- Add new File extension methods for read and write files to host
- Add JwtService for create and validate JwtTokens