Chd.Library.Security 8.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Chd.Library.Security --version 8.0.3                
NuGet\Install-Package Chd.Library.Security -Version 8.0.3                
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="Chd.Library.Security" Version="8.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chd.Library.Security --version 8.0.3                
#r "nuget: Chd.Library.Security, 8.0.3"                
#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 Chd.Library.Security as a Cake Addin
#addin nuget:?package=Chd.Library.Security&version=8.0.3

// Install Chd.Library.Security as a Cake Tool
#tool nuget:?package=Chd.Library.Security&version=8.0.3                

Security library for .Net Core

Chd (cleverly handle difficulty) library helps you cleverly handle difficulty, writing code fastly and do your application stable.

๐Ÿ“ Table of Contents

๐Ÿง About

This library provides authorization and authentication. It also provides IP filtering through its middleware. The library using JWT authorization works by encoding information into a JSON web token (JWT), which is then passed between the client and server. The steps involved in a typical JWT authorization flow are as follows: Authentication: The client sends the userโ€™s credentials to the server, which authenticates the user and generates a JWT containing information about the user. Issuing the Token: The server sends the JWT back to the client, which stores it for future use. Sending the Token: When the client wants to access a protected resource on the server, it sends the JWT in the Authorization header of the HTTP request. Verifying the Token: The server receives the request and verifies the JWT by checking its signature using the secret key that was used to sign it. If the JWT is valid, the server extracts the information contained in it and uses it to determine what actions the user is authorized to perform. Authorizing the Request: If the user is authorized to access the resource, the server returns the requested data. If the user is not authorized, the server returns an error message. Made up of three components, a header, a payload, and a signature, it's becoming more and more commonly used.

๐Ÿ Getting Started

JWT authorization enables secure and efficient communication between the client and server, as the server does not need to store any session information to keep track of the userโ€™s authentication status. This makes it ideal for use in microservice architectures and other decentralized systems, where multiple independent components need to communicate with each other in a secure manner.

Prerequisites

You must use .net core 8.0 or higher

๐ŸŽˆ Usage

You must have published a service that generates JWT tokens. You must enter that link in the configuration below.

Apsettings Configurations

You must add code below in appsettings.json

"Jwt": {
    "Key": "SECRET_KEY",
    "Issuer": "http://your_token_builder_link",
    "Audience": "audience"
  }

๐Ÿ”ง Injection Jwt Authorization Into The Project

   var builder = WebApplication.CreateBuilder(args);
   ....
   ....
   builder.UseJwtTokenAuthorization();

๐Ÿ”ง Login The System

Use the following code block to log in to the system using JWT token.

        [AllowAnonymous]
        [Route("login")]
        [HttpPost]
        public async Task<IActionResult> Login(UserModel userModel)
        {
            userModel.Password = userModel?.Password?.ToMd5();

            var isvalid = await SecurityContext.Login(this, userModel ?? new UserModel());
            if (isvalid != null)
            {
                return RedirectToAction("MainWindow");
            }
            else
            {
                return RedirectToAction("Error");
            }
        }

โœ๏ธ Authors

See also the list of contributors who participated in this project.

๐ŸŽ‰ Acknowledgements

Thank you for using my library.

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 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. 
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
9.0.3 68 1/30/2025
9.0.2 89 12/29/2024
9.0.1 79 12/29/2024
8.0.3 72 12/23/2024
8.0.0 291 1/30/2024
7.4.0 506 12/12/2023
7.3.9 623 8/9/2023
1.3.5 154 2/2/2023