Skip to content

Commit 6d8e5f6

Browse files
Microsoft Account external login: Move Portal steps to links (#34669)
* Microsoft Account external login: Move Portal steps to links * Link update * Corrected link * Improved for Acrolinx issues * Updated Portal references to Entra admin center * Update tenant portion of Wades PR (#34862) * Update date format in Microsoft logins doc * Clarify secrets and values * Update aspnetcore/security/authentication/social/microsoft-logins.md Add review suggestion, remove v6.0 mention. Co-authored-by: Rick Anderson <[email protected]> * Update aspnetcore/security/authentication/social/microsoft-logins.md Formatted ms.date value * Update ProgramMS.cs remove unneeded vars * Added snippet tag for ProgramMS.cs --------- Co-authored-by: Rick Anderson <[email protected]>
1 parent 53dc80a commit 6d8e5f6

File tree

2 files changed

+34
-67
lines changed

2 files changed

+34
-67
lines changed

aspnetcore/security/authentication/social/microsoft-logins.md

Lines changed: 27 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: rick-anderson
44
description: This sample demonstrates the integration of Microsoft account user authentication into an existing ASP.NET Core app.
55
ms.author: riande
66
ms.custom: mvc
7-
ms.date: 12/08/2021
7+
ms.date: 03/01/2025
88
monikerRange: '>= aspnetcore-3.1'
99
uid: security/authentication/microsoft-logins
1010
---
@@ -14,39 +14,23 @@ By [Valeriy Novytskyy](https://github.com/01binary) and [Rick Anderson](https://
1414

1515
:::moniker range=">= aspnetcore-6.0"
1616

17-
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).
17+
This sample shows how to enable users to sign in with their work, school, or personal Microsoft account using the ASP.NET Core project created on the [previous page](xref:security/authentication/social/index).
1818

19-
## Create the app in Microsoft Developer Portal
19+
## Create the app in the Microsoft Entra admin center
2020

2121
* Add the [Microsoft.AspNetCore.Authentication.MicrosoftAccount](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.MicrosoftAccount/) NuGet package to the project.
22-
* Navigate to the [Azure portal - App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page and create or sign into a Microsoft account:
22+
* Register the application in the Microsoft Entra admin center by following the steps in [Register an application with the Microsoft identity platform](/entra/identity-platform/quickstart-register-app?tabs=client-secret)
2323

24-
If you don't have a Microsoft account, select **Create one**. After signing in, you are redirected to the **App registrations** page:
24+
### Create a client secret
2525

26-
* Select **New registration**
27-
* Enter a **Name**.
28-
* Select an option for **Supported account types**. <!-- Accounts for any org work with MS domain accounts. Most folks probably want the last option, personal MS accounts. It took 24 hours after setting this up for the keys to work -->
29-
* The `MicrosoftAccount` package supports App Registrations created using "Accounts in any organizational directory" or "Accounts in any organizational directory and Microsoft accounts" options by default.
30-
* To use other options, set `AuthorizationEndpoint` and `TokenEndpoint` members of `MicrosoftAccountOptions` used to initialize the Microsoft Account authentication to the URLs displayed on **Endpoints** page of the App Registration after it is created (available by clicking Endpoints on the **Overview** page).
31-
* Under **Redirect URI**, enter your development URL with `/signin-microsoft` appended. For example, `https://localhost:5001/signin-microsoft`. The Microsoft authentication scheme configured later in this sample will automatically handle requests at `/signin-microsoft` route to implement the OAuth flow.
32-
* Select **Register**
33-
34-
### Create client secret
35-
36-
* In the left pane, select **Certificates & secrets**.
37-
* Under **Client secrets**, select **New client secret**
38-
* Add a description for the client secret.
39-
* Select the **Add** button.
40-
* Under **Client secrets**, copy the value of the client secret.
41-
42-
The URI segment `/signin-microsoft` is set as the default callback of the Microsoft authentication provider. You can change the default callback URI while configuring the Microsoft authentication middleware via the inherited <xref:Microsoft.AspNetCore.Authentication.RemoteAuthenticationOptions.CallbackPath%2A?displayProperty=nameWithType> property of the <xref:Microsoft.AspNetCore.Authentication.MicrosoftAccount.MicrosoftAccountOptions> class.
26+
Generate a client secret in the Microsoft Entra admin center by following the steps in [Register an application with the Microsoft identity platform: Add Credentials](/entra/identity-platform/quickstart-register-app?tabs=client-secret#add-credentials).
4327

4428
## Store the Microsoft client ID and secret
4529

46-
Store sensitive settings such as the Microsoft **Application (client) ID** found on the **Overview** page of the App Registration and **Client Secret** you created on the **Certificates & secrets page** with [Secret Manager](xref:security/app-secrets). For this sample, use the following steps:
30+
Store sensitive settings such as the Microsoft **Application (client) ID** and **Client Secret** created in the previous step with [Secret Manager](xref:security/app-secrets). For this sample, use the following steps:
4731

4832
1. Initialize the project for secret storage per the instructions at [Enable secret storage](xref:security/app-secrets#enable-secret-storage).
49-
1. Store the sensitive settings in the local secret store with the secret keys `Authentication:Microsoft:ClientId` and `Authentication:Microsoft:ClientSecret`:
33+
1. Store the sensitive settings in the local secret store with the secret keys `Authentication:Microsoft:ClientId` and `Authentication:Microsoft:ClientSecret`. The `<client-id>` is listed on the Azure App registrations blade under **Application (client) ID**. The `<client-secret>` is on listed under **Certificates & secrets** as the **Value**, not the **Secret ID**.
5034

5135
```dotnetcli
5236
dotnet user-secrets set "Authentication:Microsoft:ClientId" "<client-id>"
@@ -59,7 +43,7 @@ Store sensitive settings such as the Microsoft **Application (client) ID** found
5943
6044
Add the Authentication service to the `Program`:
6145
62-
[!code-csharp[](~/security/authentication/social/social-code/6.x/ProgramMS.cs)]
46+
:::code language="csharp" source="~/security/authentication/social/social-code/6.x/ProgramMS.cs" id="snippet_AddServices":::
6347
6448
[!INCLUDE [default settings configuration](includes/default-settings.md)]
6549
@@ -68,65 +52,49 @@ For more information about configuration options supported by Microsoft Account
6852
## Sign in with Microsoft Account
6953
7054
* Run the app and select **Log in**. An option to sign in with Microsoft appears.
71-
* 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:
72-
* Select **Yes**. You are redirected back to the web site where you can set your email.
55+
* Select to sign in with Microsoft to navigate to Microsoft for authentication. After signing in with your Microsoft Account, you'll be prompted to let the app access your info:
56+
* Select **Yes** to navigate back to the web site where to set your email.
7357
74-
You are now logged in using your Microsoft credentials.
58+
You're now logged in using your Microsoft credentials.
7559
7660
[!INCLUDE[](includes/chain-auth-providers.md)]
7761
7862
[!INCLUDE[Forward request information when behind a proxy or load balancer section](includes/forwarded-headers-middleware.md)]
7963
8064
## Troubleshooting
8165
82-
* 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.
66+
* If the Microsoft Account provider redirects to a sign in error page, note the error title and description query string parameters directly following the `#` (hashtag) in the Uri.
8367
8468
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.
8569
8670
* 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.
8771
88-
* 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.
72+
* If the site database hasn't been created by applying the initial migration, *A database operation failed while processing the request* error occurs. Tap **Apply Migrations** to create the database and refresh to continue past the error.
8973
9074
## Next steps
9175
92-
* This article showed how you can authenticate with Microsoft. You can follow a similar approach to authenticate with other providers listed on the [previous page](xref:security/authentication/social/index).
93-
* Once you publish your web site to Azure web app, create a new client secrets in the Microsoft Developer Portal.
94-
* Set the `Authentication:Microsoft:ClientId` and `Authentication:Microsoft:ClientSecret` as application settings in the Azure portal. The configuration system is set up to read keys from environment variables.
76+
* This article showed how to authenticate with Microsoft. Follow a similar approach to authenticate with other providers listed on the [previous page](xref:security/authentication/social/index).
77+
* Once the web site is published to Azure web app, create a new client secrets in the Microsoft Entra admin center.
78+
* Set the `Authentication:Microsoft:ClientId` and `Authentication:Microsoft:ClientSecret` as application settings in the Microsoft Entra admin center. The configuration system is set up to read keys from environment variables.
9579
9680
:::moniker-end
9781
9882
:::moniker range="< aspnetcore-6.0"
9983
10084
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).
10185
102-
## Create the app in Microsoft Developer Portal
86+
## Create the app in the Microsoft Entra admin center
10387
10488
* Add the [Microsoft.AspNetCore.Authentication.MicrosoftAccount](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.MicrosoftAccount/) NuGet package to the project.
105-
* Navigate to the [Azure portal - App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page and create or sign into a Microsoft account:
106-
107-
If you don't have a Microsoft account, select **Create one**. After signing in, you are redirected to the **App registrations** page:
108-
109-
* Select **New registration**
110-
* Enter a **Name**.
111-
* Select an option for **Supported account types**. <!-- Accounts for any org work with MS domain accounts. Most folks probably want the last option, personal MS accounts. It took 24 hours after setting this up for the keys to work -->
112-
* The `MicrosoftAccount` package supports App Registrations created using "Accounts in any organizational directory" or "Accounts in any organizational directory and Microsoft accounts" options by default.
113-
* To use other options, set `AuthorizationEndpoint` and `TokenEndpoint` members of `MicrosoftAccountOptions` used to initialize the Microsoft Account authentication to the URLs displayed on **Endpoints** page of the App Registration after it is created (available by clicking Endpoints on the **Overview** page).
114-
* Under **Redirect URI**, enter your development URL with `/signin-microsoft` appended. For example, `https://localhost:5001/signin-microsoft`. The Microsoft authentication scheme configured later in this sample will automatically handle requests at `/signin-microsoft` route to implement the OAuth flow.
115-
* Select **Register**
89+
* Register the application in the Microsoft Entra admin center by following the steps in [Register an application with the Microsoft identity platform](/entra/identity-platform/quickstart-register-app?tabs=client-secret#register-an-application)
11690
11791
### Create client secret
11892
119-
* In the left pane, select **Certificates & secrets**.
120-
* Under **Client secrets**, select **New client secret**
121-
* Add a description for the client secret.
122-
* Select the **Add** button.
123-
* Under **Client secrets**, copy the value of the client secret.
124-
125-
The URI segment `/signin-microsoft` is set as the default callback of the Microsoft authentication provider. You can change the default callback URI while configuring the Microsoft authentication middleware via the inherited <xref:Microsoft.AspNetCore.Authentication.RemoteAuthenticationOptions.CallbackPath%2A?displayProperty=nameWithType> property of the <xref:Microsoft.AspNetCore.Authentication.MicrosoftAccount.MicrosoftAccountOptions> class.
93+
Generate a client secret in the Microsoft Entra admin center by following the steps in [Register an application with the Microsoft identity platform: Add Credentials](/entra/identity-platform/quickstart-register-app?tabs=client-secret#add-credentials).
12694
12795
## Store the Microsoft client ID and secret
12896
129-
Store sensitive settings such as the Microsoft **Application (client) ID** found on the **Overview** page of the App Registration and **Client Secret** you created on the **Certificates & secrets page** with [Secret Manager](xref:security/app-secrets). For this sample, use the following steps:
97+
Store sensitive settings such as the Microsoft **Application (client) ID** and **Client Secret** you created in the previous step with [Secret Manager](xref:security/app-secrets). For this sample, use the following steps:
13098
13199
1. Initialize the project for secret storage per the instructions at [Enable secret storage](xref:security/app-secrets#enable-secret-storage).
132100
1. Store the sensitive settings in the local secret store with the secret keys `Authentication:Microsoft:ClientId` and `Authentication:Microsoft:ClientSecret`:
@@ -150,11 +118,11 @@ For more information about configuration options supported by Microsoft Account
150118
151119
## Sign in with Microsoft Account
152120
153-
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:
121+
Run the app and select **Log in**. An option to sign in with Microsoft appears. Select **Microsoft** to navigate to Microsoft for authentication. After signing in with your Microsoft Account, you'll be prompted to let the app access your info:
154122
155-
Tap **Yes** and you will be redirected back to the web site where you can set your email.
123+
Tap **Yes** and you'll be redirected back to the web site where you can set your email.
156124
157-
You are now logged in using your Microsoft credentials.
125+
You're now logged in using your Microsoft credentials.
158126
159127
[!INCLUDE[](includes/chain-auth-providers.md)]
160128
@@ -166,12 +134,12 @@ You are now logged in using your Microsoft credentials.
166134
167135
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.
168136
* 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.
169-
* 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.
137+
* If the site database hasn't been created by applying the initial migration, you'll get *A database operation failed while processing the request* error. Tap **Apply Migrations** to create the database and refresh to continue past the error.
170138
171139
## Next steps
172140
173141
* This article showed how you can authenticate with Microsoft. You can follow a similar approach to authenticate with other providers listed on the [previous page](xref:security/authentication/social/index).
174-
* Once you publish your web site to Azure web app, create a new client secrets in the Microsoft Developer Portal.
175-
* Set the `Authentication:Microsoft:ClientId` and `Authentication:Microsoft:ClientSecret` as application settings in the Azure portal. The configuration system is set up to read keys from environment variables.
142+
* Once you publish your web site to Azure web app, create a new client secrets in the Microsoft Entra admin center.
143+
* Set the `Authentication:Microsoft:ClientId` and `Authentication:Microsoft:ClientSecret` as application settings in Microsoft Entra admin center. The configuration system is set up to read keys from environment variables.
176144
177145
:::moniker-end
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
var builder = WebApplication.CreateBuilder(args);
2-
var services = builder.Services;
3-
var configuration = builder.Configuration;
4-
5-
services.AddAuthentication().AddMicrosoftAccount(microsoftOptions =>
6-
{
7-
microsoftOptions.ClientId = configuration["Authentication:Microsoft:ClientId"];
8-
microsoftOptions.ClientSecret = configuration["Authentication:Microsoft:ClientSecret"];
9-
});
2+
// <snippet_AddServices>
3+
builder.Services.AddAuthentication().AddMicrosoftAccount(microsoftOptions =>
4+
{
5+
microsoftOptions.ClientId = configuration["Authentication:Microsoft:ClientId"];
6+
microsoftOptions.ClientSecret = configuration["Authentication:Microsoft:ClientSecret"];
7+
});
8+
// </snippet_AddServices>

0 commit comments

Comments
 (0)