Authentication Using Facebook In ASP.NET Core

Introduction

In this post, we will see how to add Facebook Login to your .Net Core project

Let us start.

Facebook Developer Application Registration

If you are going to use Facebook for the Developers portal for the first time, you need to register first.

Go to:https://developers.facebook.com/apps/

Click on Register Now(make sure you are logged in on Facebook),

After login, you get the following Page on the screen :

Step 1: Click on ‘My apps‘ which is on the top right corner

Step 2: Click on the ‘create app’ Button which is on the top right corner of the screen ad you get the following pop-up

Step 3: Now select the ‘None’ option from the pop-up and click on ‘continue’

State 4: Add Your Application name and click on ‘Create app

Note: Enter your password for confirmation if they ask for it

Step 5: Select ‘Facebook login card’s set up button’

Step 6: Now go to Setting > Basic :

Now copy App ID and App Secret key

Step 7: Now Open Your .net core application and right-click on the application :

Now select ‘manage user secrets’ when you click on this option you get a secret.json file on your editor

Add the following code into a secret.json file

{
  "Authentication:Facebook:AppSecret": "Your AppSecret",
  "Authentication:Facebook:AppId": "Your AppId"
}

Step 7: Once the keys are added, open Startup.cs class and add the below lines into the ‘ConfigureServices’ function

Here you need to install a package to your solution: “Microsoft.AspNetCore.Authentication.Facebook”

services.AddAuthentication().AddFacebook(facebookOptions =>  
{  
    facebookOptions.AppId = Configuration["Authentication:Facebook:AppId"];  
    facebookOptions.AppSecret = Configuration["Authentication:Facebook:AppSecret"];  
});

Step 8: Now open your Facebook support portal and follow the following steps shown in the image:

Note :    Add “/signin-Facebook” and add

For Ex: “https://localhost:44356/signin-facebook”

And add your URL Like this in “Valid OAuth Redirect URIs”

Now run your application And you redirected to the home page of your application

When you click on the Sign-in button you will redirect to the following page:

That’s it

Now you can see Your Facebook authentication button for login in with Facebook.

you can register and log in with Facebook from your ASP.NET core application.

Follow upper steps for adding Facebook authentication in your core project follow all steps and read all the lines of a blog.

I hope you can resolve your problem from this blog

Thank you.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories