Skip to main content

Posts

Showing posts with the label Asp.Net Core

Part-6 | Blazor WebAssembly | .Net7 API | MudBlazor | CRUD - Implement Delete Operation

The main objectives of this article are: Create A HTTP Delete Endpoint In API Project Consume HTTP Delete Endpoint In Blazor WebAssembly Application. Create A HTTP Delete Endpoint In API Project: Let's add a method definition like the 'DeleteSuperHeroesAsync()' method in the 'ISuperHeroesService'. API_Project/Services/ISuperHeroesService.cs: Task<int> DeleteSuperHeroesAsync(int id); Let's implement the 'DeleteSuperHeroesAsync()' method in the 'SuperHeroesService.cs' API_Project/Services/SuperHeroesService.cs: public async Task<int> DeleteSuperHeroesAsync(int id) { await _myWorldDbContext.SuperHeroes.Where(_ => _.Id == id).ExecuteDeleteAsync(); return id; } Here using entity framework core method 'ExecuteDeleteAsync' for deleting the item from the database. Invoke The HTTP Delete Endpoint In The Blazor WebAssembly Application: First, let's create a delete confirmation popup for that let's create a new comp

Part - 7 | Asp.Net Core Identity Series[.NET 7] | Twitter Authentication

The main objectives of this article are: Implementing Twitter Authentication. Install Twitter Authentication NuGet Package: Let's install the required package for Twitter authentication. Visual Studio 2022: Install-Package Microsoft.AspNetCore.Authentication.Twitter -Version 7.0.4 Visual Studio Code: dotnet add package Microsoft.AspNetCore.Authentication.Twitter --version 7.0.4 Register Our App With Twitter: To enable Twitter authentication to our application we have to register our API with Twitter. So following are steps to register with Twitter. (Step 1) Register with 'Twitter Developers' section and then navigate to the dashboard page 'https://developer.twitter.com/en/portal/dashboard' (Step 2) Click on 'Create Poject' on the dashboard page. (Step 3) Specify the project name and then click on the 'Next' button. (Step 4) Select a use case and then click on the 'Next' button (Step 5) Provide some project description and then click o

Part - 6 | Asp.Net Core Identity Series[.NET 7] | Facebook Authentication

The main objective of this article is: Implementing Facebook Authentication Install Facebook Authentication NuGet Package: Let's install the required package for Facebook authentication. Visual Studio 2022: Install-Package Microsoft.AspNetCore.Authentication.Facebook -Version 7.0.4 Visual Studio Code: Install-Package Microsoft.AspNetCore.Authentication.Facebook -Version 7.0.4 Register Our App With Facebook: To enable Facebook authentication we have to register our API project with Facebook. So following are Facebook registration steps. (Step 1) Go to the Facebook developer page 'https://developers.facebook.com/apps/'. (Step 2) Go to the 'My Apps' menu and click on the 'Create App' button. (Step 3) In the 'Create An App' section, choose the 'Consumer' option and finally click on the 'Next' button. (Step 4) Enter a name for the 'Add an app name' and click on 'Create app'. (Step 5) On 'Add products to your app

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