Enabling Facebook middleware

ASP.NET Core comes up with some out-of-the-box external authentication middleware to authenticate users from Facebook, Twitter, Microsoft account, and Google. To implement Facebook authentication, we have to add a NuGet package--MicrosoftAspNetCore.Authentication.Facebook

Then, add the following code snippet to the Configure method of the Startup class:

    app.UseFacebookAuthentication(new FacebookOptions() 
{
AppId = Configuration["your_app_id"],
AppSecret = Configuration["your_app_secret"]
});

In the preceding code snippet, we are setting the Facebook App ID and Facebook Secret Key using the FacebookOptions object.

Now, when you run your application, it will show the Facebook button, as shown in the following screenshot:

Clicking on the Facebook button will get the authentication code from Facebook and render the Facebook authentication page where a user can specify the login credentials and proceed.

It will ask you to allow to access the profile information and on allowing, redirects to the website. Finally, it prompts you to complete the registration:

On clicking on Register, it will create the user in the ASP.NET Identity database. For Identity user you can specify any other username as well and use that credential to log in next time with local Identity authentication.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.98.148