Skip to content

Commit 9a58f2e

Browse files
authored
Blazor with OIDC v2.0 endpoint coverage (#18308)
1 parent 3f9b34d commit 9a58f2e

2 files changed

Lines changed: 91 additions & 2 deletions

File tree

aspnetcore/security/blazor/server/additional-scenarios.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to configure Blazor Server for additional security scenar
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 04/27/2020
8+
ms.date: 05/19/2020
99
no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR]
1010
uid: security/blazor/server/additional-scenarios
1111
---
@@ -136,3 +136,64 @@ public class WeatherForecastService
136136
}
137137
}
138138
```
139+
140+
## Use Open ID Connect (OIDC) v2.0 endpoints
141+
142+
The authentication library and Blazor templates use Open ID Connect (OIDC) v1.0 endpoints. To use a v2.0 endpoint, configure the <xref:Microsoft.AspNetCore.Builder.OpenIdConnectOptions.Authority?displayProperty=nameWithType> option in the <xref:Microsoft.AspNetCore.Builder.OpenIdConnectOptions>:
143+
144+
```csharp
145+
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme,
146+
options =>
147+
{
148+
options.Authority += "/v2.0";
149+
}
150+
```
151+
152+
Alternatively, the setting can be made in the app settings (*appsettings.json*) file:
153+
154+
```json
155+
{
156+
"AzureAd": {
157+
"Authority": "https://login.microsoftonline.com/common/oauth2/v2.0/",
158+
...
159+
}
160+
}
161+
```
162+
163+
If tacking on a segment to the authority isn't appropriate for the app's OIDC provider, such as with non-AAD providers, set the `Authority` property directly. Either set the property in <xref:Microsoft.AspNetCore.Builder.OpenIdConnectOptions> or in the app settings file with the `Authority` key.
164+
165+
### Code changes
166+
167+
* The list of claims in the ID token changes for v2.0 endpoints. For more information, see [Why update to Microsoft identity platform (v2.0)?](/azure/active-directory/azuread-dev/azure-ad-endpoint-comparison) in the Azure documentation.
168+
* Since resources are specified in scope URIs for v2.0 endpoints, remove the the <xref:Microsoft.AspNetCore.Builder.OpenIdConnectOptions.Resource?displayProperty=nameWithType> property setting in <xref:Microsoft.AspNetCore.Builder.OpenIdConnectOptions>:
169+
170+
```csharp
171+
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
172+
{
173+
...
174+
options.Resource = "..."; // REMOVE THIS LINE
175+
...
176+
}
177+
```
178+
179+
For more information, see [Scopes, not resources](/azure/active-directory/azuread-dev/azure-ad-endpoint-comparison#scopes-not-resources) in the Azure documentation.
180+
181+
### App ID URI
182+
183+
* When using v2.0 endpoints, APIs define an *App ID URI*, which is meant to represent a unique identifier for the API.
184+
* All scopes include the App ID URI as a prefix, and v2.0 endpoints emit access tokens with the App ID URI as the audience.
185+
* When using V2.0 endpoints, the client ID configured in the Server API changes from the API Application ID (Client ID) to the App ID URI.
186+
187+
*appsettings.json*:
188+
189+
```json
190+
{
191+
"AzureAd": {
192+
...
193+
"ClientId": "https://{TENANT}.onmicrosoft.com/{APP NAME}"
194+
...
195+
}
196+
}
197+
```
198+
199+
You can find the App ID URI to use in the OIDC provider app registration description.

aspnetcore/security/blazor/webassembly/additional-scenarios.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to configure Blazor WebAssembly for additional security s
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: riande
77
ms.custom: mvc
8-
ms.date: 05/11/2020
8+
ms.date: 05/19/2020
99
no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR]
1010
uid: security/blazor/webassembly/additional-scenarios
1111
---
@@ -818,3 +818,31 @@ While this approach requires an extra network hop through the server to call a t
818818

819819
* The server can store refresh tokens and ensure that the app doesn't lose access to third-party resources.
820820
* The app can't leak access tokens from the server that might contain more sensitive permissions.
821+
822+
## Use Open ID Connect (OIDC) v2.0 endpoints
823+
824+
The authentication library and Blazor templates use Open ID Connect (OIDC) v1.0 endpoints. To use a v2.0 endpoint, configure the JWT Bearer <xref:Microsoft.AspNetCore.Builder.JwtBearerOptions.Authority?displayProperty=nameWithType> option. In the following example, AAD is configured for v2.0 by appending a `v2.0` segment to the `Authority` property:
825+
826+
```csharp
827+
builder.Services.Configure<JwtBearerOptions>(
828+
AzureADDefaults.JwtBearerAuthenticationScheme,
829+
options =>
830+
{
831+
options.Authority += "/v2.0";
832+
});
833+
```
834+
835+
Alternatively, the setting can be made in the app settings (*appsettings.json*) file:
836+
837+
```json
838+
{
839+
"Local": {
840+
"Authority": "https://login.microsoftonline.com/common/oauth2/v2.0/",
841+
...
842+
}
843+
}
844+
```
845+
846+
If tacking on a segment to the authority isn't appropriate for the app's OIDC provider, such as with non-AAD providers, set the `Authority` property directly. Either set the property in `JwtBearerOptions` or in the app settings file with the `Authority` key.
847+
848+
The list of claims in the ID token changes for v2.0 endpoints. For more information, see [Why update to Microsoft identity platform (v2.0)?](/azure/active-directory/azuread-dev/azure-ad-endpoint-comparison).

0 commit comments

Comments
 (0)