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
Copy file name to clipboardExpand all lines: articles/active-directory/develop/scenario-web-app-sign-user-app-configuration.md
+27-35Lines changed: 27 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ ms.service: active-directory
9
9
ms.subservice: develop
10
10
ms.topic: conceptual
11
11
ms.workload: identity
12
-
ms.date: 07/14/2020
12
+
ms.date: 12/8/2022
13
13
ms.author: jmprieur
14
14
ms.custom: aaddev, devx-track-python
15
15
#Customer intent: As an application developer, I want to know how to write a web app that signs in users by using the Microsoft identity platform.
@@ -64,8 +64,16 @@ You might want to refer to this sample for full implementation details.
64
64
65
65
Web applications that sign in users by using the Microsoft identity platform are configured through configuration files. These are the values you're required to specify in the configuration:
66
66
67
-
- The cloud instance (`Instance`) if you want your app to run in national clouds, for example
68
-
- The audience in the tenant ID (`TenantId`)
67
+
- The cloud instance (`Instance`) if you want your app to run in national clouds, for example. The different options include;
68
+
-`https://login.microsoftonline.com/` for Azure public cloud
69
+
-`https://login.microsoftonline.us/` for Azure US government
70
+
-`https://login.microsoftonline.de/` for Azure AD Germany
71
+
-`https://login.partner.microsoftonline.cn/common` for Azure AD China operated by 21Vianet
72
+
- The audience in the tenant ID (`TenantId`). The options vary depending on whether your app is single tenant or multitenant.
73
+
-`TenantId` for a GUID obtained from the Azure portal to sign in users in your organization. You can also use a domain name.
74
+
-`organizations` to sign in users in any work or school account
75
+
-`common` to sign in users with any work or school account or Microsoft personal account
76
+
-`consumers` to sign in users with a Microsoft personal account only
69
77
- The client ID (`ClientId`) for your application, as copied from the Azure portal
70
78
71
79
You might also see references to the `Authority`. The `Authority` value is the concatenation of the `Instance` and `TenantId` values.
@@ -77,22 +85,11 @@ In ASP.NET Core, these settings are located in the [appsettings.json](https://gi
77
85
```Json
78
86
{
79
87
"AzureAd": {
80
-
// Azure cloud instance among:
81
-
// - "https://login.microsoftonline.com/" for Azure public cloud
82
-
// - "https://login.microsoftonline.us/" for Azure US government
83
-
// - "https://login.microsoftonline.de/" for Azure AD Germany
84
-
// - "https://login.partner.microsoftonline.cn/common" for Azure AD China operated by 21Vianet
85
88
"Instance": "https://login.microsoftonline.com/",
86
-
87
-
// Azure AD audience among:
88
-
// - "TenantId" as a GUID obtained from the Azure portal to sign in users in your organization
89
-
// - "organizations" to sign in users in any work or school account
90
-
// - "common" to sign in users with any work or school account or Microsoft personal account
91
-
// - "consumers" to sign in users with a Microsoft personal account only
92
89
"TenantId": "[Enter the tenantId here]",
93
90
94
91
// Client ID (application ID) obtained from the Azure portal
95
-
"ClientId": "[Enter the Client Id]",
92
+
"ClientId": "[Enter the Client Id here]",
96
93
"CallbackPath": "/signin-oidc",
97
94
"SignedOutCallbackPath": "/signout-oidc"
98
95
}
@@ -131,7 +128,7 @@ In ASP.NET Core, another file ([properties\launchSettings.json](https://github.c
131
128
}
132
129
```
133
130
134
-
In the Azure portal, the redirect URIs that you register on the **Authentication** page for your application need to match these URLs. For the two preceding configuration files, they would be `https://localhost:44321/signin-oidc`. The reason is that `applicationUrl` is `http://localhost:3110`, but `sslPort` is specified (44321). `CallbackPath` is `/signin-oidc`, as defined in `appsettings.json`.
131
+
In the Azure portal, the redirect URIs that you register on the **Authentication** page for your application need to match these URLs. For the two preceding configuration files, they would be `https://localhost:44321/signin-oidc`. The reason is that `applicationUrl` is `http://localhost:3110`, but `sslPort` is specified (`44321`). `CallbackPath` is `/signin-oidc`, as defined in `appsettings.json`.
135
132
136
133
In the same way, the sign-out URI would be set to `https://localhost:44321/signout-oidc`.
137
134
> [!NOTE]
@@ -189,8 +186,7 @@ These parameters are used to create a configuration object in *authConfig.js* fi
189
186
190
187
In the Azure portal, the reply URIs that you register on the Authentication page for your application need to match the redirectUri instances that the application defines (`http://localhost:3000/auth/redirect`).
191
188
192
-
> [!NOTE]
193
-
> This quickstart proposes to store the client secret in the configuration file for simplicity. In your production app, you'd want to use other ways to store your secret, such as a key vault or an environment variable.
189
+
For simplicity in this article, the client secret is stored in the configuration file. In the production app, consider using a key vault or an environment variable. An even better option is to use a certificate.
SESSION_TYPE="filesystem"# So the token cache will be stored in a server-side session
206
202
```
207
203
208
-
> [!NOTE]
209
-
> This quickstart proposes to store the client secret in the configuration file for simplicity. In your production app, you'd want to use other ways to store your secret, such as a key vault or an environment variable as described in [Flask's documentation](https://flask.palletsprojects.com/en/1.1.x/config/#configuring-from-environment-variables).
210
-
>
211
-
> ```python
212
-
>CLIENT_SECRET= os.getenv("CLIENT_SECRET")
213
-
>ifnotCLIENT_SECRET:
214
-
>raiseValueError("Need to define CLIENT_SECRET environment variable")
215
-
>```
204
+
For simplicity in this article, the client secret is stored in the configuration file. In the production app, consider using a key vault or an environment variable as described in [Flask's documentation](https://flask.palletsprojects.com/en/1.1.x/config/#configuring-from-environment-variables) to store your secret.
205
+
206
+
```python
207
+
CLIENT_SECRET= os.getenv("CLIENT_SECRET")
208
+
ifnotCLIENT_SECRET:
209
+
raiseValueError("Need to define CLIENT_SECRET environment variable")
210
+
```
216
211
217
212
---
218
213
219
214
## Initialization code
220
215
221
-
The initialization code is different depending on the platform. For ASP.NET Core andASP.NET, signing in users is delegated to the OpenID Connect middleware. The ASP.NETorASP.NET Core template generates web applications for the Azure Active Directory (Azure AD) v1.0 endpoint. Some configuration is required to adapt them to the Microsoft identity platform. In the case of Java, it's handled by Spring with the cooperation of the application.
216
+
The initialization code differences are platform dependant. For ASP.NET Core and ASP.NET, signing in users is delegated to the OpenID Connect middleware. The ASP.NET or ASP.NET Core template generates web applications for the Azure Active Directory (Azure AD) v1.0 endpoint. Some configuration is required to adapt them to the Microsoft identity platform.
222
217
223
218
# [ASP.NET Core](#tab/aspnetcore)
224
219
225
-
In ASP.NET Core web apps (and web APIs), the application is protected because you have a `[Authorize]` attribute on the controllers or the controller actions. This attribute checks that the user is authenticated. Prior to the release of .NET6, the code that's initializing the application is in the *Startup.cs* file. New ASP.NET Core projects with .NET 6 no longer contain a *Startup.cs* file. Taking its place is the *Program.cs* file. The rest of this tutorial pertains to .NET 5 or lower.
226
-
227
-
To add authentication with the Microsoft identity platform (formerly Azure AD v2.0), you'll need to add the following code. The comments in the code should be self-explanatory.
220
+
In ASP.NET Core web apps (and web APIs), the application is protected because you have a `Authorize` attribute on the controllers or the controller actions. This attribute checks that the user is authenticated. Prior to the release of .NET 6, the code initializaation wis in the *Startup.cs* file. New ASP.NET Core projects with .NET 6 no longer contain a *Startup.cs* file. Taking its place is the *Program.cs* file. The rest of this tutorial pertains to .NET 5 or lower.
228
221
229
222
> [!NOTE]
230
-
> If you want to start directly with the new ASP.NET Core templates for Microsoft identity platform, that leverage Microsoft.Identity.Web, you can download a preview NuGet package containing project templates for .NETCore 3.1and .NET5.0. Then, once installed, you can directly instantiate ASP.NET Core web applications (MVCor Blazor). See [Microsoft.Identity.Web web app project templates](https://aka.ms/ms-id-web/webapp-project-templates) for details. This is the simplest approach as it will do all the steps below for you.
223
+
> If you want to start directly with the new ASP.NET Core templates for Microsoft identity platform, that leverage Microsoft.Identity.Web, you can download a preview NuGet package containing project templates for .NET 5.0. Then, once installed, you can directly instantiate ASP.NET Core web applications (MVC or Blazor). See [Microsoft.Identity.Web web app project templates](https://aka.ms/ms-id-web/webapp-project-templates) for details. This is the simplest approach as it will do all the steps below for you.
231
224
>
232
225
> If you prefer to start your project with the current default ASP.NET Core web project within Visual Studio or by using `dotnet new mvc --auth SingleOrg` or `dotnet new webapp --auth SingleOrg`, you'll see code like the following:
233
226
>
@@ -237,9 +230,8 @@ To add authentication with the Microsoft identity platform (formerly Azure AD v2
1. Add the [Microsoft.Identity.Web](https://www.nuget.org/packages/Microsoft.Identity.Web) and [Microsoft.Identity.Web.UI](https://www.nuget.org/packages/Microsoft.Identity.Web.UI) NuGet packages to your project. Remove the Microsoft.AspNetCore.Authentication.AzureAD.UI NuGet package if it is present.
234
+
1. Addthe [Microsoft.Identity.Web](https://www.nuget.org/packages/Microsoft.Identity.Web) and [Microsoft.Identity.Web.UI](https://www.nuget.org/packages/Microsoft.Identity.Web.UI) NuGet packages to your project. Remove the `Microsoft.AspNetCore.Authentication.AzureAD.UI` NuGet package if it is present.
243
235
244
236
2. Updatethecodein `ConfigureServices` sothatitusesthe `AddMicrosoftIdentityWebAppAuthentication` and `AddMicrosoftIdentityUI` methods.
245
237
@@ -278,7 +270,7 @@ To add authentication with the Microsoft identity platform (formerly Azure AD v2
278
270
```
279
271
280
272
Inthecodeabove:
281
-
- The `AddMicrosoftIdentityWebAppAuthentication` extension method is defined in**Microsoft.Identity.Web**. It:
0 commit comments