Posts

ASP.NET Core 8: Creating Custom Authentication Handler for Authenticating Users for the Minimal APIs

Image
The ASP.NET Core is the superb technology for building modern web apps. One of the best features of ASP.ET Core is the ease of security implementation and its customization as per the application requirements. The Identity Object model of ASP.NET Core provides extensive customization to the developers so that they can implement the security logic as per the application's requirements where the Identity can be verified against the On-Premises and/or Cloud stores where the Users' credentials are kept.  In this article we will see an implementation of the custom Authentication Handler to handle the authorization of the request to the Minimal APIs. The Figure 1 provides an idea of the implementation Figure 1: The Authentication Handlers in ASP.NET Core Minimal APIs To implement custom authentication handler, we will be using the following classes: AuthenticationSchemeOptions:   This class is used to set the scheme for the authentication calls. The request to the API will be forward

ASP.NET Core 8: Model Validations in Minimal APIs using Endpoint Filters

Image
Minimal API is the great features of ASP.NET Core. This feature provides a better mechanism to create APIs with less complex code than the traditional controllers' approach. Minimal APIs provides simple and clean code to define HTTP Endpoints. In the case of Minimal APIs, we directly focus on the domain implementation rather than controllers and its actions methods. Minimal APIs offers readability, Testability, as well as they offer an easy approach for building APIs for new professionals.  While implementing APIs, it is important to implement the Model Data Validations to make sure that the data received is valid before it is considered for processing. While using the Minimal APIs, we need to use the Fluent Validations to validate the model data. In this article, we will perform the Model Validation using the FluentValidation package as well as using the Endpoint Filter. The Figure 1 will provide an idea of the Validation in ASP.NET Core Minimal API. Figure 1: The Validation Step

ASP.NET Core: Performing the Model Validations in ASP.NET Core using Action Filters

Image
 In this article, we will see how we can validate the model data in ASP.NET Core API. In ASP.NET Core Actions filters  allows  code to run before or after specific stages in the request processing pipeline.  There build-in filters provided in ASP.NET Core for Authorization, Resources, Exception, etc. We can create the  Custom filters those are used to handle cross-cutting concerns. For example, custom error handling, caching, configuration, authorization, and logging. Action Filters are used to avoid duplicating code. Data Validation is the most important and mandatory part of the application development. This prevents the invalid data to be accepted and processed by the application system. In ASP.NET Core, we have data annotations to validate Model properties. We can apply data annotations on Model properties if we have access to Model classes, but what if we do not have access to it, in this case we need to implement validations using Fluent Validation techniques. In .NET Core we hav

ASP.NET Core API: Returning Video File as stream and playing video stream in Angular Client Application

Image
In this article, we explore an implementation that involves serving a video file from an ASP.NET Core API as a stream and playing it within an Angular client application. Our goal is to demonstrate how to create a stream response from the API and seamlessly deliver it to the client.  During the development of server-side APIs, we often encounter scenarios where users need to download files in client applications. However, when dealing with large files, it’s more efficient to use streamed responses. For instance, if the file is a video, rather than downloading it to the client, we can directly play it in the video player within the client  application. In ASP.NET Core, the  FileStreamResult   object is utilized to write stream data to the response. This approach allows sending binary content using a  Stream  instance when returning a file as a  FileStream . Figure 1 illustrates the high-level implementation concept. Figure 1: ASP.NET Core API returning Stream to Angular Client Step 1: C

Accessing Azure SQL Connection String from Azure Key Vault in ASP.NET Core API

Image
In this article, we will see the use of Azure Key Vault access in ASP.NET Core application. Azure Key Vault is a cloud service for securely storing and accessing secrets. A secret is anything that we want to tightly control access to, such as Database Connection Strings, API Auth keys, passwords, certificates, cryptographic keys, etc. The Azure Key Vault helps to solve problems as follows: Secrets Management  - It can be used to Securely store and tightly control access to tokens, passwords, certificates, API keys, and other secrets like Database Connection String Key Management  - It can be used as a Key Management solution. Azure Key Vault makes it easy to create and control the encryption keys used to encrypt the data of the Application. Certificate Management  - It allows an easy provision, manage, and deploy public and private Transport Layer Security/Secure Sockets Layer (TLS/SSL) certificates for use with Azure.   More information of Azure Key Vault can be read from this link .