You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.NET 6.0 Update for Social Login Tutorials (#24242)
* Updated instructions and code snippets for social authentication in .net 6 (ms, facebook, google and twitter)
* Update microsoft-logins.md
Moniker issue is blocking the build, but a little strange since it looks OK to me. Testing with a more explicit > 3.0 and < 6.0 range.
* Update microsoft-logins.md
Reverted back to original moniker that received a build warning.
* Update facebook-logins.md
Removed specific mention of 3.0
* Update google-logins.md
Removed specific mention of 3.0
* Update microsoft-logins.md
Removed specific mention of 3.0
* Update twitter-logins.md
Removed specific mention of 3.0
* .NET 6 update Social Login Tutorials
* Edit pass
Co-authored-by: Johan Danforth <[email protected]>
@@ -17,31 +17,32 @@ By [Valeriy Novytskyy](https://github.com/01binary) and [Rick Anderson](https://
17
17
<!-- 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.
18
18
-->
19
19
20
-
This tutorial with code examples shows how to enable your users to sign in with their Facebook account using a sample ASP.NET Core 3.0 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).
20
+
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).
21
21
22
22
## Create the app in Facebook
23
23
24
24
* Add the [Microsoft.AspNetCore.Authentication.Facebook](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Facebook) NuGet package to the project.
25
25
26
26
* 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.
27
27
28
-
* From the **My Apps** menu select **Create App** to create a new App ID.
29
-
28
+
* From the **My Apps** menu select **Create App**. The **Create an app** form appears.
30
29

31
30
32
-
* Fill out the form and tap the **Create App ID** button.
31
+
* Select an app type that best fits your project. For this project, select **Consumer**, and then **Next**. A new App ID is created.
32
+
33
+
* Fill out the form and tap the **Create App** button.
33
34
34
35

35
36
36
-
* On the new App card, select **Add a Product**. On the **Facebook Login** card, click **Set Up**
37
+
* On the **Add Products to Your App** page, select **Set Up** on the **Facebook Login** card.
* 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:
@@ -50,13 +51,13 @@ This tutorial with code examples shows how to enable your users to sign in with
50
51
> [!NOTE]
51
52
> 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 [RemoteAuthenticationOptions.CallbackPath](/dotnet/api/microsoft.aspnetcore.authentication.remoteauthenticationoptions.callbackpath) property of the [FacebookOptions](/dotnet/api/microsoft.aspnetcore.authentication.facebook.facebookoptions) class.
52
53
53
-
*Click**Save Changes**.
54
+
*Select**Save Changes**.
54
55
55
-
*Click**Settings** > **Basic** link in the left navigation.
56
+
*Select**Settings** > **Basic** link in the left navigation.
56
57
57
-
On this page, 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:
58
+
* 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:
58
59
59
-
* When deploying the site you need to revisit the **Facebook Login** setup page and register a new public URI.
60
+
* When deploying the site you need to revisit the **Facebook Login** setup page, and register a new public URI.
60
61
61
62
## Store the Facebook app ID and secret
62
63
@@ -74,7 +75,9 @@ Store sensitive settings such as the Facebook app ID and secret values with [Sec
74
75
75
76
## Configure Facebook Authentication
76
77
77
-
Add the Facebook service in the `ConfigureServices` method in the *Startup.cs* file:
78
+
::: moniker range="< aspnetcore-6.0"
79
+
80
+
Add the Authentication service to the `Startup.ConfigureServices`:
We recommend the `AccessDeniedPath` page contain the following information:
122
+
We recommend the `AccessDeniedPath` page contains the following information:
110
123
111
124
* Remote authentication was canceled.
112
125
* This app requires authentication.
@@ -124,7 +137,7 @@ We recommend the `AccessDeniedPath` page contain the following information:
124
137
125
138
[!INCLUDE[](includes/chain-auth-providers.md)]
126
139
127
-
See the [FacebookOptions](/dotnet/api/microsoft.aspnetcore.builder.facebookoptions) API reference for more information on configuration options supported by Facebook authentication. Configuration options can be used to:
140
+
For more information on configuration options supported by Facebook authentication, see the [FacebookOptions](/dotnet/api/microsoft.aspnetcore.builder.facebookoptions) API reference. Configuration options can be used to:
128
141
129
142
* Request different information about the user.
130
143
* Add query string arguments to customize the login experience.
By [Valeriy Novytskyy](https://github.com/01binary) and [Rick Anderson](https://twitter.com/RickAndMSFT)
14
14
15
-
This tutorial shows you how to enable users to sign in with their Google account using the ASP.NET Core 3.0 project created on the [previous page](xref:security/authentication/social/index).
15
+
This tutorial shows you how to enable users to sign in with their Google account using the ASP.NET Core project created on the [previous page](xref:security/authentication/social/index).
16
16
17
17
## Create a Google API Console project and client ID
18
18
19
19
* Add the [Microsoft.AspNetCore.Authentication.Google](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Google) NuGet package to the app.
20
+
20
21
* Follow the guidance in [Integrating Google Sign-In into your web app](https://developers.google.com/identity/sign-in/web/sign-in) (Google documentation).
21
-
* In the **Credentials** page of the [Google console](https://console.developers.google.com/apis/credentials), select **CREATE CREDENTIALS** > **OAuth client ID**.
22
-
* In the **Application type** dialog, select **Web application**. Provide a **Name** for the app.
22
+
23
+
* Go to [Google API & Services](https://console.cloud.google.com/apis).
24
+
25
+
* A **Project** must exist first, you may have to create one. Just a name is required. Once a project is selected, you will enter the **Dashboard**.
26
+
27
+
* In the **Oauth consent screen** of the **Dashboard**:
28
+
* Select **User Type - External** and **CREATE**.
29
+
* In the **App information** dialog, Provide an **app name** for the app, **user support email**, and **developer contact information**.
30
+
* Step through the **Scopes** step.
31
+
* Step through the **Test users** step.
32
+
* Review the **OAuth consent screen** and go back to the app **Dashboard**.
33
+
34
+
35
+
* In the **Credentials** tab of the application Dashboard, select **CREATE CREDENTIALS** > **OAuth client ID**.
36
+
37
+
* Select **Application type** > **Web application**, choose a **name**.
38
+
23
39
* In the **Authorized redirect URIs** section, select **ADD URI** to set the redirect URI. Example redirect URI: `https://localhost:{PORT}/signin-google`, where the `{PORT}` placeholder is the app's port.
40
+
24
41
* Select the **CREATE** button.
42
+
25
43
* Save the **Client ID** and **Client Secret** for use in the app's configuration.
44
+
26
45
* When deploying the site, either:
27
46
* Update the app's redirect URI in the **Google Console** to the app's deployed redirect URI.
28
47
* Create a new Google API registration in the **Google Console** for the production app with its production redirect URI.
@@ -45,23 +64,35 @@ You can manage your API credentials and usage in the [API Console](https://conso
45
64
46
65
## Configure Google authentication
47
66
48
-
Add the Google service to `Startup.ConfigureServices`:
67
+
::: moniker range="< aspnetcore-6.0"
68
+
69
+
Add the Authentication service to the `Startup.ConfigureServices`:
* Run the app and click **Log in**. An option to sign in with Google appears.
57
-
* Click the **Google** button, which redirects to Google for authentication.
87
+
* Run the app and select **Log in**. An option to sign in with Google appears.
88
+
* Select the **Google** button, which redirects to Google for authentication.
58
89
* After entering your Google credentials, you are redirected back to the web site.
59
90
60
91
[!INCLUDE[Forward request information when behind a proxy or load balancer section](includes/forwarded-headers-middleware.md)]
61
92
62
93
[!INCLUDE[](includes/chain-auth-providers.md)]
63
94
64
-
See the <xref:Microsoft.AspNetCore.Authentication.Google.GoogleOptions> API reference for more information on configuration options supported by Google authentication. This can be used to request different information about the user.
95
+
For more information on configuration options supported by Google authentication, see the <xref:Microsoft.AspNetCore.Authentication.Google.GoogleOptions> API reference . This can be used to request different information about the user.
65
96
66
97
## Change the default callback URI
67
98
@@ -70,7 +101,7 @@ The URI segment `/signin-google` is set as the default callback of the Google au
70
101
## Troubleshooting
71
102
72
103
* If the sign-in doesn't work and you aren't getting any errors, switch to development mode to make the issue easier to debug.
73
-
* If Identity isn't configured by calling `services.AddIdentity` in `ConfigureServices`, attempting to authenticate results in *ArgumentException: The 'SignInScheme' option must be provided*. The project template used in this tutorial ensures that this is done.
104
+
* If Identity isn't configured by calling `services.AddIdentity` in `ConfigureServices`, attempting to authenticate results in *ArgumentException: The 'SignInScheme' option must be provided*. The project template used in this tutorial ensures Identity is configured.
74
105
* If the site database has not been created by applying the initial migration, you get *A database operation failed while processing the request* error. Select **Apply Migrations** to create the database, and refresh the page to continue past the error.
@@ -15,7 +15,7 @@ By [Valeriy Novytskyy](https://github.com/01binary) and [Rick Anderson](https://
15
15
16
16
:::moniker range=">= aspnetcore-6.0"
17
17
18
-
This sample shows you how to enable users to sign in with their work, school, or personal Microsoft account using the ASP.NET Core 3.0 project created on the [previous page](xref:security/authentication/social/index).
18
+
This sample shows you how to enable users to sign in with their work, school, or personal Microsoft account using the ASP.NET Core 6.0 project created on the [previous page](xref:security/authentication/social/index).
19
19
20
20
## Create the app in Microsoft Developer Portal
21
21
@@ -58,19 +58,19 @@ Store sensitive settings such as the Microsoft **Application (client) ID** found
58
58
59
59
## Configure Microsoft Account Authentication
60
60
61
-
Add the Microsoft Account service to the `Startup.ConfigureServices`:
For more information about configuration options supported by Microsoft Account authentication, see the [MicrosoftAccountOptions](/dotnet/api/microsoft.aspnetcore.builder.microsoftaccountoptions) API reference. This can be used to request different information about the user.
68
68
69
69
## Sign in with Microsoft Account
70
70
71
-
Run the app and click **Log in**. An option to sign in with Microsoft appears. When you click on Microsoft, you are redirected to Microsoft for authentication. After signing in with your Microsoft Account, you will be prompted to let the app access your info:
72
-
73
-
Tap **Yes** and you will be redirected back to the web site where you can set your email.
71
+
* Run the app and select **Log in**. An option to sign in with Microsoft appears.
72
+
* Select to sign in with Microsoft. You are redirected to Microsoft for authentication. After signing in with your Microsoft Account, you will be prompted to let the app access your info:
73
+
* Select **Yes**. You are redirected back to the web site where you can set your email.
74
74
75
75
You are now logged in using your Microsoft credentials:
76
76
@@ -83,7 +83,9 @@ You are now logged in using your Microsoft credentials:
83
83
* If the Microsoft Account provider redirects you to a sign in error page, note the error title and description query string parameters directly following the `#` (hashtag) in the Uri.
84
84
85
85
Although the error message seems to indicate a problem with Microsoft authentication, the most common cause is your application Uri not matching any of the **Redirect URIs** specified for the **Web** platform.
86
+
86
87
* 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 sample ensures that this is done.
88
+
87
89
* If the site database has not been created by applying the initial migration, you will get *A database operation failed while processing the request* error. Tap **Apply Migrations** to create the database and refresh to continue past the error.
88
90
89
91
## Next steps
@@ -149,7 +151,7 @@ For more information about configuration options supported by Microsoft Account
149
151
150
152
## Sign in with Microsoft Account
151
153
152
-
Run the app and click **Log in**. An option to sign in with Microsoft appears. When you click on Microsoft, you are redirected to Microsoft for authentication. After signing in with your Microsoft Account, you will be prompted to let the app access your info:
154
+
Run the app and select **Log in**. An option to sign in with Microsoft appears. When you select on Microsoft, you are redirected to Microsoft for authentication. After signing in with your Microsoft Account, you will be prompted to let the app access your info:
153
155
154
156
Tap **Yes** and you will be redirected back to the web site where you can set your email.
0 commit comments