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', Click on the 'Setup' button on the 'Facebook Login' card.
(Step 6)
The 'Facebook Login' menu is on the left-hand side, under it click on the 'Settings' tab.
(Step 7)
On 'Client OAuth Settings', add the 'Valid OAuth Redirect URLs' like '{domain}/singin-facebook'. Here '/signin-facebook' path is the default redirection path for the Facebook provider.
(Step 8)
Now left-side menu 'Settings' then select 'Basic' option, Here we have two keys we need to configure into our razor page application like 'App Id', 'App Secret'.
Add Facebook Setting To Our Project:
Let's add the Facebook settings like 'App Id', 'App Secret' in 'app settings.Development.json'.
appsettings.Development.json:
"FacebookSettings":{ "AppId":"xxxxxxxxxx", "AppSecret":"xxxxxxxxxxxx" }.
Register Facebook Authentication Service:
Let's register the Facebook authentication service in our 'Program.cs'.
Program.cs:
builder.Services.AddAuthentication() .AddFacebook(fbOptions => { fbOptions.AppId = builder.Configuration.GetSection("FacebookSettings") .GetValue<string>("AppId"); fbOptions.AppSecret = builder.Configuration.GetSection("FacebookSettings") .GetValue<string>("AppSecret"); });
- (Line: 2-7) Registered 'Facebook' service by configuring the 'AppId' & 'AppSecret'.
Test Facebook Authentication Flow:
(Step 1)
On enabling the facebook authentication service we can see a 'Facebook' login button on both 'Login' & 'Registration' Pages.
(Step 2)
On clicking the 'Facebook' button we will redirect to the Facebook login page.
(Step 3)Next, it explicitly asks us to associate an email address with our application.
(Step 4)
On Clciking 'Register' button we can observe user information added to 'AspNetUser' and 'AspNetUserLogin' tables
(Step 5)
After email confirmation, If we try to login , we can observe we get authenticated as below.
In the next article, we are going to do Twitter authentication with asp.net core identity
Support Me!
Buy Me A Coffee
PayPal Me
Video Session:
Wrapping Up:
Hopefully, I think this article delivered some useful information on the Asp.Net Core Identity In Razor Pages. using I love to have your feedback, suggestions, and better techniques in the comment section below
Refer:
Part-2 | Asp.Net Core Identity Series[.NET 7] | Registration Email Confirmation
Part-3 | Asp.Net Core Identity Series[.NET 7] | Sending Two-Factor Authentication(2FA) Code To Email
Part-3 | Asp.Net Core Identity Series[.NET 7] | Sending Two-Factor Authentication(2FA) Code To Email
Part-4 | Asp.Net Core Identity Series[.NET 7] | Sending Two-Factor Authentication(2FA) Code To Phone
Part-5 | Asp.Net Core Identity Series[.NET 7] | Google Authentication
Part - 7 | Asp.Net Core Identity Series[.NET 7] | Twitter Authentication
Part - 7 | Asp.Net Core Identity Series[.NET 7] | Twitter Authentication
Comments
Post a Comment