Skip to content

Commit 99efbbe

Browse files
authored
Blazor security guidance updates (#17608)
1 parent 2e6dd3e commit 99efbbe

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

aspnetcore/security/blazor/webassembly/hosted-with-azure-active-directory-b2c.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description:
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 03/30/2020
8+
ms.date: 04/04/2020
99
no-loc: [Blazor, SignalR]
1010
uid: security/blazor/webassembly/hosted-with-azure-active-directory-b2c
1111
---
@@ -111,20 +111,20 @@ To specify the output location, which creates a project folder if it doesn't exi
111111

112112
### Authentication package
113113

114-
The support for authenticating and authorizing calls to ASP.NET Core Web APIs is provided by the `Microsoft.AspNetCore.Authentication.AzureAD.UI`:
114+
The support for authenticating and authorizing calls to ASP.NET Core Web APIs is provided by the `Microsoft.AspNetCore.Authentication.AzureADB2C.UI`:
115115

116116
```xml
117-
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI"
117+
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureADB2C.UI"
118118
Version="3.1.0" />
119119
```
120120

121121
### Authentication service support
122122

123-
The `AddAuthentication` method sets up authentication services within the app and configures the JWT Bearer handler as the default authentication method. The `AddAzureADBearer` method sets up the specific parameters in the JWT Bearer handler required to validate tokens emitted by the Azure Active Directory:
123+
The `AddAuthentication` method sets up authentication services within the app and configures the JWT Bearer handler as the default authentication method. The `AddAzureADBearer` method sets up the specific parameters in the JWT Bearer handler required to validate tokens emitted by the Azure Active Directory B2C:
124124

125125
```csharp
126-
services.AddAuthentication(AzureADDefaults.BearerAuthenticationScheme)
127-
.AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
126+
services.AddAuthentication(AzureADB2CDefaults.BearerAuthenticationScheme)
127+
.AddAzureADB2CBearer(options => Configuration.Bind("AzureAdB2C", options));
128128
```
129129

130130
`UseAuthentication` and `UseAuthorization` ensure that:
@@ -137,6 +137,20 @@ app.UseAuthentication();
137137
app.UseAuthorization();
138138
```
139139

140+
### User.Identity.Name
141+
142+
By default, the `User.Identity.Name` isn't populated.
143+
144+
To configure the app to receive the value from the `name` claim type, configure the [TokenValidationParameters.NameClaimType](xref:Microsoft.IdentityModel.Tokens.TokenValidationParameters.NameClaimType) of the <xref:Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerOptions> in `Startup.ConfigureServices`:
145+
146+
```csharp
147+
services.Configure<JwtBearerOptions>(
148+
AzureADB2CDefaults.JwtBearerAuthenticationScheme, options =>
149+
{
150+
options.TokenValidationParameters.NameClaimType = "name";
151+
});
152+
```
153+
140154
### App settings
141155

142156
The *appsettings.json* file contains the options to configure the JWT bearer handler used to validate access tokens.
@@ -263,8 +277,9 @@ builder.Services.AddMsalAuthentication(options =>
263277

264278
Run the app from the Server project. When using Visual Studio, select the Server project in **Solution Explorer** and select the **Run** button in the toolbar or start the app from the **Debug** menu.
265279

280+
<!-- HOLD
266281
[!INCLUDE[](~/includes/blazor-security/usermanager-signinmanager.md)]
267-
282+
-->
268283
[!INCLUDE[](~/includes/blazor-security/troubleshoot.md)]
269284

270285
## Additional resources

aspnetcore/security/blazor/webassembly/hosted-with-azure-active-directory.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description:
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 03/30/2020
8+
ms.date: 04/04/2020
99
no-loc: [Blazor, SignalR]
1010
uid: security/blazor/webassembly/hosted-with-azure-active-directory
1111
---
@@ -132,6 +132,20 @@ app.UseAuthentication();
132132
app.UseAuthorization();
133133
```
134134

135+
### User.Identity.Name
136+
137+
By default, the Server app API populates `User.Identity.Name` with the value from the `http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name` claim type (for example, `2d64b3da-d9d5-42c6-9352-53d8df33d770@contoso.onmicrosoft.com`).
138+
139+
To configure the app to receive the value from the `name` claim type, configure the [TokenValidationParameters.NameClaimType](xref:Microsoft.IdentityModel.Tokens.TokenValidationParameters.NameClaimType) of the <xref:Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerOptions> in `Startup.ConfigureServices`:
140+
141+
```csharp
142+
services.Configure<JwtBearerOptions>(
143+
AzureADDefaults.JwtBearerAuthenticationScheme, options =>
144+
{
145+
options.TokenValidationParameters.NameClaimType = "name";
146+
});
147+
```
148+
135149
### App settings
136150

137151
The *appsettings.json* file contains the options to configure the JWT bearer handler used to validate access tokens.
@@ -259,7 +273,9 @@ builder.Services.AddMsalAuthentication(options =>
259273

260274
Run the app from the Server project. When using Visual Studio, select the Server project in **Solution Explorer** and select the **Run** button in the toolbar or start the app from the **Debug** menu.
261275

276+
<!-- HOLD
262277
[!INCLUDE[](~/includes/blazor-security/usermanager-signinmanager.md)]
278+
-->
263279

264280
[!INCLUDE[](~/includes/blazor-security/troubleshoot.md)]
265281

0 commit comments

Comments
 (0)