Skip to content

Commit 427ffc7

Browse files
Merge pull request #220880 from cilwerner/content-health-1
[GTD][Core content][content-health] - scenario-web-app-sign-user-app-configuration.md - remove .NET 3.1 reference + article is +365 days stale
2 parents 8577afc + 0865fa2 commit 427ffc7

File tree

1 file changed

+27
-35
lines changed

1 file changed

+27
-35
lines changed

articles/active-directory/develop/scenario-web-app-sign-user-app-configuration.md

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.service: active-directory
99
ms.subservice: develop
1010
ms.topic: conceptual
1111
ms.workload: identity
12-
ms.date: 07/14/2020
12+
ms.date: 12/8/2022
1313
ms.author: jmprieur
1414
ms.custom: aaddev, devx-track-python
1515
#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.
6464

6565
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:
6666

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
6977
- The client ID (`ClientId`) for your application, as copied from the Azure portal
7078

7179
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
7785
```Json
7886
{
7987
"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
8588
"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
9289
"TenantId": "[Enter the tenantId here]",
9390

9491
// Client ID (application ID) obtained from the Azure portal
95-
"ClientId": "[Enter the Client Id]",
92+
"ClientId": "[Enter the Client Id here]",
9693
"CallbackPath": "/signin-oidc",
9794
"SignedOutCallbackPath": "/signout-oidc"
9895
}
@@ -131,7 +128,7 @@ In ASP.NET Core, another file ([properties\launchSettings.json](https://github.c
131128
}
132129
```
133130

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`.
135132

136133
In the same way, the sign-out URI would be set to `https://localhost:44321/signout-oidc`.
137134
> [!NOTE]
@@ -189,8 +186,7 @@ These parameters are used to create a configuration object in *authConfig.js* fi
189186

190187
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`).
191188

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.
194190

195191
# [Python](#tab/python)
196192

@@ -205,29 +201,26 @@ SCOPE = ["User.ReadBasic.All"]
205201
SESSION_TYPE = "filesystem" # So the token cache will be stored in a server-side session
206202
```
207203

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-
> if not CLIENT_SECRET:
214-
> raise ValueError("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+
if not CLIENT_SECRET:
209+
raise ValueError("Need to define CLIENT_SECRET environment variable")
210+
```
216211

217212
---
218213

219214
## Initialization code
220215

221-
The initialization code is different depending on the platform. 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. 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.
222217

223218
# [ASP.NET Core](#tab/aspnetcore)
224219

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 .NET 6, 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.
228221

229222
> [!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 .NET Core 3.1 and .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.
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.
231224
>
232225
> 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:
233226
>
@@ -237,9 +230,8 @@ To add authentication with the Microsoft identity platform (formerly Azure AD v2
237230
> ```
238231
>
239232
> This code uses the legacy **Microsoft.AspNetCore.Authentication.AzureAD.UI** NuGet package which is used to create an Azure AD v1.0 application. This article explains how to create a Microsoft identity platform (Azure AD v2.0) application which replaces that code.
240-
>
241233
242-
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. 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.
243235
244236
2. Update the code in `ConfigureServices` so that it uses the `AddMicrosoftIdentityWebAppAuthentication` and `AddMicrosoftIdentityUI` methods.
245237
@@ -278,7 +270,7 @@ To add authentication with the Microsoft identity platform (formerly Azure AD v2
278270
```
279271
280272
In the code above:
281-
- The `AddMicrosoftIdentityWebAppAuthentication` extension method is defined in **Microsoft.Identity.Web**. It:
273+
- The `AddMicrosoftIdentityWebAppAuthentication` extension method is defined in **Microsoft.Identity.Web**, which;
282274
- Adds the authentication service.
283275
- Configures options to read the configuration file (here from the "AzureAD" section)
284276
- Configures the OpenID Connect options so that the authority is the Microsoft identity platform.
@@ -381,7 +373,7 @@ Move on to the next article in this scenario,
381373
# [Node.js](#tab/nodejs)
382374
383375
Move on to the next article in this scenario,
384-
[Sign in](./scenario-web-app-sign-user-sign-in.md?tabs=nodejs).
376+
[Sign in and sign out](./scenario-web-app-sign-user-sign-in.md?tabs=nodejs).
385377
386378
# [Python](#tab/python)
387379

0 commit comments

Comments
 (0)