"
 
 
 
ASP.NET (snapshot 2017) Microsoft documentation and samples

Configuring Facebook authentication

By Valeriy Novytskyy and Rick Anderson

This tutorial shows you how to enable your users to sign in with their Facebook account using a sample ASP.NET Core 2.0 project created on the previous page. We start by creating a Facebook App ID by following the official steps.

Create the app in Facebook

Client OAuth Settings page
Client OAuth Settings page

Store Facebook App ID and App Secret

Link sensitive settings like Facebook App ID and App Secret to your application configuration using the (xref:)Secret Manager. For the purposes of this tutorial, name the tokens Authentication:Facebook:AppId and Authentication:Facebook:AppSecret.

Execute the following commands to securely store App ID and App Secret using Secret Manager:

dotnet user-secrets set Authentication:Facebook:AppId <app-id>
dotnet user-secrets set Authentication:Facebook:AppSecret <app-secret>

Configure Facebook Authentication

The project template used in this tutorial ensures that Microsoft.AspNetCore.Authentication.Facebook package is already installed.

ASP.NET Core 2.x

Add the Facebook service in the ConfigureServices method in the Startup.cs file:

[!INCLUDEdefault settings configuration]

ASP.NET Core 1.x

Add the Facebook middleware in the Configure method in Startup.cs file:


See the FacebookOptions API reference for more information on configuration options supported by Facebook authentication. Configuration options can be used to:

Sign in with Facebook

Run your application and click Log in. You see an option to sign in with Facebook.

Web application: User not authenticated
Web application: User not authenticated

When you click on Facebook, you are redirected to Facebook for authentication:

Facebook authentication page
Facebook authentication page

Facebook authentication requests public profile and email address by default:

Facebook authentication page
Facebook authentication page

Once you enter your Facebook credentials you are redirected back to your site where you can set your email.

You are now logged in using your Facebook credentials:

Web application: User authenticated
Web application: User authenticated

Troubleshooting

Next steps





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnetcore/security/authentication/social/facebook-logins.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>