Chd.Library.Security
9.0.2
See the version list below for details.
dotnet add package Chd.Library.Security --version 9.0.2
NuGet\Install-Package Chd.Library.Security -Version 9.0.2
<PackageReference Include="Chd.Library.Security" Version="9.0.2" />
paket add Chd.Library.Security --version 9.0.2
#r "nuget: Chd.Library.Security, 9.0.2"
// Install Chd.Library.Security as a Cake Addin #addin nuget:?package=Chd.Library.Security&version=9.0.2 // Install Chd.Library.Security as a Cake Tool #tool nuget:?package=Chd.Library.Security&version=9.0.2
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 9.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
- Mehmet YoldaΕ - Linkedin
See also the list of contributors who participated in this project.
π Acknowledgements
Thank you for using my library.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net9.0
- Chd.Library.Common (>= 9.0.7)
- GSS.Authentication.CAS.AspNetCore (>= 5.3.3)
- Microsoft.AspNetCore (>= 2.2.0)
- Microsoft.AspNetCore.Authentication (>= 2.2.0)
- Microsoft.AspNetCore.Authentication.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Authentication.Cookies (>= 2.2.0)
- Microsoft.AspNetCore.Authentication.Core (>= 2.2.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.1)
- Microsoft.AspNetCore.Authorization.Policy (>= 2.2.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.1)
- Microsoft.Extensions.Configuration.FileExtensions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Json (>= 8.0.0)
- Microsoft.Extensions.FileProviders.Abstractions (>= 8.0.0)
- Microsoft.Extensions.FileProviders.Physical (>= 8.0.0)
- Microsoft.Extensions.FileSystemGlobbing (>= 8.0.0)
- Microsoft.Extensions.Primitives (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.