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
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]>
Copy file name to clipboardExpand all lines: aspnetcore/security/authentication/social/microsoft-logins.md
+27-59Lines changed: 27 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ author: rick-anderson
4
4
description: This sample demonstrates the integration of Microsoft account user authentication into an existing ASP.NET Core app.
5
5
ms.author: riande
6
6
ms.custom: mvc
7
-
ms.date: 12/08/2021
7
+
ms.date: 03/01/2025
8
8
monikerRange: '>= aspnetcore-3.1'
9
9
uid: security/authentication/microsoft-logins
10
10
---
@@ -14,39 +14,23 @@ By [Valeriy Novytskyy](https://github.com/01binary) and [Rick Anderson](https://
14
14
15
15
:::moniker range=">= aspnetcore-6.0"
16
16
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).
18
18
19
-
## Create the app in Microsoft Developer Portal
19
+
## Create the app in the Microsoft Entra admin center
20
20
21
21
* 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)
23
23
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
25
25
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).
43
27
44
28
## Store the Microsoft client ID and secret
45
29
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:
47
31
48
32
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**.
50
34
51
35
```dotnetcli
52
36
dotnet user-secrets set "Authentication:Microsoft:ClientId" "<client-id>"
@@ -59,7 +43,7 @@ Store sensitive settings such as the Microsoft **Application (client) ID** found
@@ -68,65 +52,49 @@ For more information about configuration options supported by Microsoft Account
68
52
## Sign in with Microsoft Account
69
53
70
54
* 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.
73
57
74
-
You are now logged in using your Microsoft credentials.
58
+
You're now logged in using your Microsoft credentials.
75
59
76
60
[!INCLUDE[](includes/chain-auth-providers.md)]
77
61
78
62
[!INCLUDE[Forward request information when behind a proxy or load balancer section](includes/forwarded-headers-middleware.md)]
79
63
80
64
## Troubleshooting
81
65
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.
83
67
84
68
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.
85
69
86
70
* 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.
87
71
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.
89
73
90
74
## Next steps
91
75
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.
95
79
96
80
:::moniker-end
97
81
98
82
:::moniker range="< aspnetcore-6.0"
99
83
100
84
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).
101
85
102
-
## Create the app in Microsoft Developer Portal
86
+
## Create the app in the Microsoft Entra admin center
103
87
104
88
* 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)
116
90
117
91
### Create client secret
118
92
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).
126
94
127
95
## Store the Microsoft client ID and secret
128
96
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:
130
98
131
99
1. Initialize the project for secret storage per the instructions at [Enable secret storage](xref:security/app-secrets#enable-secret-storage).
132
100
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
150
118
151
119
## Sign in with Microsoft Account
152
120
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:
154
122
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.
156
124
157
-
You are now logged in using your Microsoft credentials.
125
+
You're now logged in using your Microsoft credentials.
158
126
159
127
[!INCLUDE[](includes/chain-auth-providers.md)]
160
128
@@ -166,12 +134,12 @@ You are now logged in using your Microsoft credentials.
166
134
167
135
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.
168
136
* 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.
170
138
171
139
## Next steps
172
140
173
141
* 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.
0 commit comments