|
1 | 1 | --- |
2 | 2 | title: Facebook external login setup in ASP.NET Core |
| 3 | +ai-usage: ai-assisted |
3 | 4 | author: wadepickett |
4 | 5 | description: Tutorial with code examples demonstrating the integration of Facebook account user authentication into an existing ASP.NET Core app. |
5 | | -ms.author: wpickett |
6 | | -ms.custom: mvc, sfi-image-nochange |
7 | | -ms.date: 12/08/2021 |
8 | 6 | monikerRange: '>= aspnetcore-3.0' |
| 7 | +ms.author: wpickett |
| 8 | +ms.custom: mvc |
| 9 | +ms.date: 02/27/2026 |
9 | 10 | uid: security/authentication/facebook-logins |
10 | 11 | --- |
11 | 12 |
|
12 | 13 | # Facebook external login setup in ASP.NET Core |
13 | 14 |
|
14 | 15 | By [Valeriy Novytskyy](https://github.com/01binary) and [Rick Anderson](https://twitter.com/RickAndMSFT) |
15 | 16 |
|
16 | | -<!-- per @rick-anderson and scott addie, don't update images. Remove images and point the customer to the FB set up page. FB needs to maintain instructions to get key and secret. |
17 | | ---> |
18 | | - |
19 | | -This tutorial with code examples shows how to enable your users to sign in with their Facebook account using a sample ASP.NET Core project created on the [previous page](xref:security/authentication/social/index). We start by creating a Facebook App ID by following the [official steps](https://developers.facebook.com). |
| 17 | +This tutorial with code examples shows how to enable your users to sign in with their Facebook account using a sample ASP.NET Core project created on the [previous page](xref:security/authentication/social/index). |
20 | 18 |
|
21 | 19 | ## Create the app in Facebook |
22 | 20 |
|
23 | 21 | * Add the [Microsoft.AspNetCore.Authentication.Facebook](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Facebook) NuGet package to the project. |
24 | 22 |
|
25 | | -* Navigate to the [Facebook Developers app](https://developers.facebook.com/apps/) page and sign in. If you don't already have a Facebook account, use the **Sign up for Facebook** link on the login page to create one. Once you have a Facebook account, follow the instructions to register as a Facebook Developer. |
26 | | - |
27 | | -* From the **My Apps** menu select **Create App**. The **Create an app** form appears. |
28 | | -  |
29 | | - |
30 | | -* Select an app type that best fits your project. For this project, select **Consumer**, and then **Next**. A new App ID is created. |
31 | | - |
32 | | -* Fill out the form and tap the **Create App** button. |
33 | | - |
34 | | -  |
| 23 | +* Follow the [Facebook App Registration](https://developers.facebook.com/docs/apps/register) instructions to create a Facebook app and obtain your **App ID** and **App Secret**. |
35 | 24 |
|
36 | | -* On the **Add Products to Your App** page, select **Set Up** on the **Facebook Login** card. |
| 25 | +* Follow the [Facebook Login for Web](https://developers.facebook.com/docs/facebook-login/web) instructions to configure Facebook Login for your app. Add your development URI with */signin-facebook* appended (for example: `https://localhost:44320/signin-facebook`) to the **Valid OAuth Redirect URIs**. |
37 | 26 |
|
38 | | -  |
39 | | - |
40 | | -* The **Quickstart** wizard launches with **Choose a Platform** as the first page. Bypass the wizard for now by clicking the **FaceBook Login** **Settings** link in the menu on the lower left: |
41 | | - |
42 | | -  |
43 | | - |
44 | | -* The **Client OAuth Settings** page is presented: |
45 | | - |
46 | | -  |
47 | | - |
48 | | -* Enter your development URI with */signin-facebook* appended into the **Valid OAuth Redirect URIs** field (for example: `https://localhost:44320/signin-facebook`). The Facebook authentication configured later in this tutorial will automatically handle requests at */signin-facebook* route to implement the OAuth flow. |
| 27 | + The Facebook authentication configured later in this tutorial automatically handles requests at the */signin-facebook* route to implement the OAuth flow. |
49 | 28 |
|
50 | 29 | > [!NOTE] |
51 | 30 | > The URI */signin-facebook* is set as the default callback of the Facebook authentication provider. You can change the default callback URI while configuring the Facebook authentication middleware via the inherited <xref:Microsoft.AspNetCore.Authentication.RemoteAuthenticationOptions.CallbackPath%2A?displayProperty=nameWithType> property of the <xref:Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions> class. |
52 | 31 |
|
53 | | -* Select **Save Changes**. |
54 | | - |
55 | | -* Select **Settings** > **Basic** link in the left navigation. |
| 32 | +* Follow the [Facebook Login Permissions](https://developers.facebook.com/docs/facebook-login/permissions) guide to enable the **email** permission for your app. The ASP.NET Core Facebook authentication middleware requests the `email` scope by default. If the **email** permission isn't enabled on your Facebook app, authentication may fail or the user's email address will be missing after sign-in. |
56 | 33 |
|
57 | | -* Make a note of your `App ID` and your `App Secret`. You will add both into your ASP.NET Core application in the next section: |
| 34 | +* Make a note of your **App ID** and **App Secret**. You add both into your ASP.NET Core application in the next section. |
58 | 35 |
|
59 | | -* When deploying the site you need to revisit the **Facebook Login** setup page, and register a new public URI. |
| 36 | +* When deploying the site, revisit the **Facebook Login** setup page and register a new public URI. |
60 | 37 |
|
61 | 38 | ## Store the Facebook app ID and secret |
62 | 39 |
|
@@ -106,7 +83,7 @@ Add the Authentication service to the `Program`: |
106 | 83 | * Enter your Facebook credentials. |
107 | 84 | * You are redirected back to your site where you can set your email. |
108 | 85 |
|
109 | | -You are now logged in using your Facebook credentials: |
| 86 | +You are now logged in using your Facebook credentials. |
110 | 87 |
|
111 | 88 | <a name="react"></a> |
112 | 89 |
|
@@ -143,6 +120,7 @@ For more information on configuration options supported by Facebook authenticati |
143 | 120 |
|
144 | 121 | * **ASP.NET Core 2.x only:** If Identity isn't configured by calling `services.AddIdentity` in `ConfigureServices`, attempting to authenticate will result in *ArgumentException: The 'SignInScheme' option must be provided*. The project template used in this tutorial ensures that this is done. |
145 | 122 | * If the site database has not been created by applying the initial migration, you get *A database operation failed while processing the request* error. Tap **Apply Migrations** to create the database and refresh to continue past the error. |
| 123 | +* If you receive an error during Facebook sign-in or the user's email address is missing after sign-in, verify that the **email** permission is enabled for your Facebook app. See the [Facebook Login Permissions](https://developers.facebook.com/docs/facebook-login/permissions) guide for details on enabling permissions in the Facebook Developer portal. |
146 | 124 |
|
147 | 125 | ## Next steps |
148 | 126 |
|
|
0 commit comments