Skip to main content

Posts

Showing posts with the label Dotnet6

Part-2 A Demo On JWT Access Token And Refresh Token Authentication In .NET6 Web API

In this article, we will learn the generation and usage of the refresh token in .NET6 Web API application. Click here to understand the implementation of the JWT token in .NET6 Web API. Refresh Token: When the JWT access token expires to renew it without user credentials we will use the Refresh Token. Let's understand the flow of  Refresh Token. The user sends valid 'User Name' and 'Password' to the server, then the server will generate JWT Access Token and Refresh Token sent as a response The JWT Access Token is a short live token(eg 20 minutes) and Refresh Token is a long live token(eg: 7 days) Now client application sends a JWT access token in the request header that makes the user authenticated. If the JWT token expires then the server returns 401 unauthorized responses. Then the client sends the refresh token to the server to regenerate the JWT Access token. The server validates the refresh token and returns a new JWT Access Token and a new Refresh Token as a r

Part-1 A Demo On JWT Access Token And Refresh Token Authentication In .NET6 Web API

In this article, we are going to generate JWT Access Token to authenticate users against .NET6 Web API application. JWT Token(Or Access Token): JWT Token(JSON Web Token) is a digitally signed and secured token for user validation. JWT Token building components are like: Header Payload Signature JWT Access Token Flow: User request API with user credentials API validates the user credentials and generates the JWT token returns it as a response to the client application. The client application on receiving the JWT token makes the user authenticated and sends the JWT token as a header to every subsequent API request. API reads the JWT token from the request header, then API validates the token if it is a valid token then API allows the request to consume its authorized resources. Create A .NET6 API Project: Let's create a .Net6 Web API sample application to accomplish our demo. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any.Net

A Demo In .NET6 Mock HttpClient Using XUnit

In this article, we are going to test our HttpClient instance in .NET6 application by mocking it using the XUnit. Click here for .NET6 Web API Unit testing using XUnit that covers testing for 'Controllers', 'Service Logic', 'Entity framework Core Database Context'. Create An API And Unit Test Project: Let's create a .Net6 Web API and xUnit sample applications to accomplish our demo. We can use either Visual Studio 2022 or Visual Studio Code(using .NET CLI commands) to create any.Net6 application. For this demo, I'm using the 'Visual Studio Code'(using the .NET CLI command) editor. Create a folder where we want to set up our applications. Then add a solution file by running the below command. Command To Add Solution File: dotnet new sln -n Name_of_your_solution_file Now let's create a .NET6 Web API project. dotnet new webapi -o Name_of_your_API_project Now let's create xUnit project. dotnet new xunit -o Name_of_your_API_project No

A Demo To Consume Azure Cosmos DB By .Net6 Web API

In this article, we will implement a .NET6 Web API that consumes the Azure Cosmos DB. Azure CosmosDB: Azure Cosmos DB is a fully managed NoSQL database. NoSQL says data will be stored as a key/value JSON document. Cosmos DB provides 'High Availability' and 'Low Latency' for any application. Cosmos DB is very quick in response delivering, auto-scaling, effective auto failure management, etc. Any existing application that works on different DBs can be easily migrated to Azure CosmosDB as it provides APIs for integration like 'SQL/Core API'(most recommended API, our demo uses this 'SQL/Core API'), 'MongoDB API', 'Cassandra API', 'Germlin API', 'Table API'. Let's understand the structure of the Cosmos DB: Create an Azure Cosmos Account with an appropriate subscription inside of the Azure portal. After creating the Cosmos Account, we can manage the data of our account by creating 'Database', 'Containers', an