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
@@ -96,7 +96,7 @@ The <xref:Microsoft.AspNetCore.Builder.AuthorizationEndpointConventionBuilderExt
96
96
97
97
## Configure the backend web API project (`MinimalApiJwt`)
98
98
99
-
Configure the project in the <xref:Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerOptions> of the <xref:Microsoft.Extensions.DependencyInjection.JwtBearerExtensions.AddJwtBearer%2A> call in the project's `Program` file.
99
+
Configure the project in the <xref:Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerOptions> of the <xref:Microsoft.Extensions.DependencyInjection.JwtBearerExtensions.AddJwtBearer%2A> call in the `MinimalApiJwt`project's `Program` file.
100
100
101
101
For the web API app's registration, the `Weather.Get` scope is configured in the Entra or Azure portal in **Expose an API**.
## Configure the server project (`BlazorWebAppEntra`)
146
146
147
-
<xref:Microsoft.Identity.Web.AppBuilderExtension.AddMicrosoftIdentityWebApp%2A> from [Microsoft Identity Web](/entra/msal/dotnet/microsoft-identity-web/) ([`Microsoft.Identity.Web` NuGet package](https://www.nuget.org/packages/Microsoft.Identity.Web), [API documentation](<xref:Microsoft.Identity.Web?displayProperty=fullName>)) is configured by the `AzureAd` section of the server project's `appsettings.json` file.
147
+
<xref:Microsoft.Identity.Web.AppBuilderExtension.AddMicrosoftIdentityWebApp%2A> from [Microsoft Identity Web](/entra/msal/dotnet/microsoft-identity-web/) ([`Microsoft.Identity.Web` NuGet package](https://www.nuget.org/packages/Microsoft.Identity.Web), [API documentation](<xref:Microsoft.Identity.Web?displayProperty=fullName>)) is configured in the `BlazorWebAppEntra`project's `Program` file.
148
148
149
-
Obtain the application (client) ID, tenant (publisher) domain, and directory (tenant) ID from the app's registration in the Entra or Azure portal. The App ID URI is obtained for the `Weather.Get` scope. Don't include the scope name, and there's no trailing slash.
149
+
Obtain the application (client) ID, tenant (publisher) domain, and directory (tenant) ID from the app's registration in the Entra or Azure portal. The App ID URI is obtained for the `Weather.Get` scope from the web API's registration. Don't include the scope name when taking the App ID URI from the portal.
150
150
151
-
```json
152
-
"AzureAd": {
153
-
"CallbackPath": "/signin-oidc",
154
-
"ClientId": "{CLIENT ID}",
155
-
"Domain": "{TENANT DOMAIN}",
156
-
"Instance": "https://login.microsoftonline.com/",
157
-
"ResponseType": "code",
158
-
"TenantId": "{TENANT ID}"
159
-
},
160
-
...
161
-
"DownstreamApi": {
162
-
"BaseUrl": "{BASE ADDRESS}",
163
-
"Scopes": [ "{APP ID URI}/{SCOPE NAME}" ]
164
-
}
151
+
In the `BlazorWebAppEntra` project's `Program` file, provide the values for the following placeholders in Microsoft Identity Web configuration:
configOptions.Scopes= [ "{APP ID URI}/Weather.Get" ];
169
+
})
170
+
.AddInMemoryTokenCaches();
165
171
```
166
172
167
-
Placeholders in the preceding example:
173
+
Placeholders in the preceding configuration:
168
174
169
-
*`{CLIENT ID}`: The application (client) ID.
170
-
*`{TENANT DOMAIN}`: The tenant (publisher) domain.
175
+
*`{CLIENT ID (BLAZOR APP)}`: The application (client) ID.
176
+
*`{DIRECTORY NAME}`: The directory name of the tenant (publisher) domain.
171
177
*`{TENANT ID}`: The directory (tenant) ID.
172
178
*`{BASE ADDRESS}`: The web API's base address.
173
-
*`{APP ID URI}`: The App ID URI for web API scopes.
174
-
*`{SCOPE NAME}`: A scope name.
179
+
*`{APP ID URI}`: The App ID URI for web API scopes. Either of the following formats are used, where the `{CLIENT ID (WEB API)}` placeholder is the Client Id of the web API's Entra registration, and the `{DIRECTORY NAME}` placeholder is the directory name of the tenant (publishers) domain (example: `contoso`).
180
+
* ME-ID tenant format: `api://{CLIENT ID (WEB API)}`
181
+
* B2C tenant format: `https://{DIRECTORY NAME}.onmicrosoft.com/{CLIENT ID (WEB API)}`
@@ -293,7 +304,7 @@ The <xref:Microsoft.AspNetCore.Builder.AuthorizationEndpointConventionBuilderExt
293
304
294
305
## Configure the backend web API project (`MinimalApiJwt`)
295
306
296
-
Configure the project in the <xref:Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerOptions> of the <xref:Microsoft.Extensions.DependencyInjection.JwtBearerExtensions.AddJwtBearer%2A> call in the project's `Program` file.
307
+
Configure the `MinimalApiJwt`project in the <xref:Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerOptions> of the <xref:Microsoft.Extensions.DependencyInjection.JwtBearerExtensions.AddJwtBearer%2A> call in the project's `Program` file.
297
308
298
309
For the web API app's registration, the `Weather.Get` scope is configured in the Entra or Azure portal in **Expose an API**.
## Configure the server project (`BlazorWebAppEntra`)
343
354
344
-
<xref:Microsoft.Identity.Web.AppBuilderExtension.AddMicrosoftIdentityWebApp%2A> from [Microsoft Identity Web](/entra/msal/dotnet/microsoft-identity-web/) ([`Microsoft.Identity.Web` NuGet package](https://www.nuget.org/packages/Microsoft.Identity.Web), [API documentation](<xref:Microsoft.Identity.Web?displayProperty=fullName>)) is configured by the `AzureAd` section of the server project's `appsettings.json` file.
355
+
<xref:Microsoft.Identity.Web.AppBuilderExtension.AddMicrosoftIdentityWebApp%2A> from [Microsoft Identity Web](/entra/msal/dotnet/microsoft-identity-web/) ([`Microsoft.Identity.Web` NuGet package](https://www.nuget.org/packages/Microsoft.Identity.Web), [API documentation](<xref:Microsoft.Identity.Web?displayProperty=fullName>)) is configured in the `BlazorWebAppEntra`project's `Program` file.
345
356
346
-
Obtain the application (client) ID, tenant (publisher) domain, and directory (tenant) ID from the app's registration in the Entra or Azure portal. The App ID URI is obtained for the `Weather.Get` scope. Don't include the scope name, and there's no trailing slash.
357
+
Obtain the application (client) ID, tenant (publisher) domain, and directory (tenant) ID from the app's registration in the Entra or Azure portal. The App ID URI is obtained for the `Weather.Get` scope from the web API's registration. Don't include the scope name when taking the App ID URI from the portal.
347
358
348
-
```json
349
-
"AzureAd": {
350
-
"CallbackPath": "/signin-oidc",
351
-
"ClientId": "{CLIENT ID}",
352
-
"Domain": "{TENANT DOMAIN}",
353
-
"Instance": "https://login.microsoftonline.com/",
354
-
"ResponseType": "code",
355
-
"TenantId": "{TENANT ID}"
356
-
},
357
-
...
358
-
"DownstreamApi": {
359
-
"BaseUrl": "{BASE ADDRESS}",
360
-
"Scopes": [ "{APP ID URI}/{SCOPE}" ]
361
-
}
359
+
In the `BlazorWebAppEntra` project's `Program` file, provide the values for the following placeholders in Microsoft Identity Web configuration:
configOptions.Scopes= [ "{APP ID URI}/Weather.Get" ];
377
+
})
378
+
.AddInMemoryTokenCaches();
362
379
```
363
380
364
-
Placeholders in the preceding example:
381
+
Placeholders in the preceding configuration:
365
382
366
-
*`{CLIENT ID}`: The application (client) ID.
367
-
*`{TENANT DOMAIN}`: The tenant (publisher) domain.
383
+
*`{CLIENT ID (BLAZOR APP)}`: The application (client) ID.
384
+
*`{DIRECTORY NAME}`: The directory name of the tenant (publisher) domain.
368
385
*`{TENANT ID}`: The directory (tenant) ID.
369
386
*`{BASE ADDRESS}`: The web API's base address.
370
-
*`{APP ID URI}`: The App ID URI for web API scopes.
371
-
*`{SCOPE NAME}`: A scope name.
387
+
*`{APP ID URI}`: The App ID URI for web API scopes. Either of the following formats are used, where the `{CLIENT ID (WEB API)}` placeholder is the Client Id of the web API's Entra registration, and the `{DIRECTORY NAME}` placeholder is the directory name of the tenant (publishers) domain (example: `contoso`).
388
+
* ME-ID tenant format: `api://{CLIENT ID (WEB API)}`
389
+
* B2C tenant format: `https://{DIRECTORY NAME}.onmicrosoft.com/{CLIENT ID (WEB API)}`
The callback path (`CallbackPath`) must match the redirect URI (login callback path) configured when registering the application in the Entra or Azure portal. Paths are configured in the **Authentication** blade of the app's registration. The default value of `CallbackPath` is `/signin-oidc` for a registered redirect URI of `https://localhost/signin-oidc` (a port isn't required).
394
416
395
-
The <xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions.SignedOutCallbackPath%2A>(configuration key: "`SignedOutCallbackPath`") is the request path within the app's base path intercepted by the OpenID Connect handler where the user agent is first returned after signing out from Entra. The sample app doesn't set a value for the path because the default value of "`/signout-callback-oidc`" is used. After intercepting the request, the OpenID Connect handler redirects to the <xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions.SignedOutRedirectUri%2A> or <xref:Microsoft.AspNetCore.Authentication.AuthenticationProperties.RedirectUri%2A>, if specified.
417
+
The <xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions.SignedOutCallbackPath%2A> is the request path within the app's base path intercepted by the OpenID Connect handler where the user agent is first returned after signing out from Entra. The sample app doesn't set a value for the path because the default value of "`/signout-callback-oidc`" is used. After intercepting the request, the OpenID Connect handler redirects to the <xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectOptions.SignedOutRedirectUri%2A> or <xref:Microsoft.AspNetCore.Authentication.AuthenticationProperties.RedirectUri%2A>, if specified.
396
418
397
419
Configure the signed-out callback path in the app's Entra registration. In the Entra or Azure portal, set the path in the **Web** platform configuration's **Redirect URI** entries:
398
420
@@ -538,6 +560,127 @@ In the `Program` file, all claims are serialized by setting <xref:Microsoft.AspN
538
560
539
561
:::moniker-end
540
562
563
+
## Supply configuration with the JSON configuration provider (app settings)
564
+
565
+
The [sample solution projects](#sample-solution) configure Microsoft Identity Web and JWT bearer authentication in their `Program` files in order to make configuration settings discoverable using C# autocompletion. Professional apps usually use a *configuration provider* to configure OIDC options, such as the default [JSON configuration provider](xref:fundamentals/configuration/index). The JSON configuration provider loads configuration from app settings files `appsettings.json`/`appsettings.{ENVIRONMENT}.json`, where the `{ENVIRONMENT}` placeholder is the app's [runtime environment](xref:fundamentals/environments). Follow the guidance in this section to use app settings files for configuration.
566
+
567
+
In the app settings file (`appsettings.json`) of the `BlazorWebAppEntra` project, add the following JSON configuration:
568
+
569
+
```json
570
+
{
571
+
"AzureAd": {
572
+
"CallbackPath": "/signin-oidc",
573
+
"ClientId": "{CLIENT ID (BLAZOR APP)}",
574
+
"Domain": "{DIRECTORY NAME}.onmicrosoft.com",
575
+
"Instance": "https://login.microsoftonline.com/",
576
+
"ResponseType": "code",
577
+
"TenantId": "{TENANT ID}"
578
+
},
579
+
"DownstreamApi": {
580
+
"BaseUrl": "{BASE ADDRESS}",
581
+
"Scopes": [ "{APP ID URI}/Weather.Get" ]
582
+
}
583
+
}
584
+
```
585
+
586
+
Update the placeholders in the preceding configuration to match the values that the app uses in the `Program` file:
587
+
588
+
*`{CLIENT ID (BLAZOR APP)}`: The application (client) ID.
589
+
*`{DIRECTORY NAME}`: The directory name of the tenant (publisher) domain.
590
+
*`{TENANT ID}`: The directory (tenant) ID.
591
+
*`{BASE ADDRESS}`: The web API's base address.
592
+
*`{APP ID URI}`: The App ID URI for web API scopes. Either of the following formats are used, where the `{CLIENT ID (WEB API)}` placeholder is the Client Id of the web API's Entra registration, and the `{DIRECTORY NAME}` placeholder is the directory name of the tenant (publishers) domain (example: `contoso`).
593
+
* ME-ID tenant format: `api://{CLIENT ID (WEB API)}`
594
+
* B2C tenant format: `https://{DIRECTORY NAME}.onmicrosoft.com/{CLIENT ID (WEB API)}`
Audience formats adopt the following patterns (`{CLIENT ID}` is the Client Id of the web API; `{DIRECTORY NAME}` is the directory name, for example, `contoso`):
The configuration is automatically picked up by the JWT bearer authentication builder.
671
+
672
+
Remove the following lines from the `Program` file:
673
+
674
+
```diff
675
+
- jwtOptions.Authority = "...";
676
+
- jwtOptions.Audience = "...";
677
+
```
678
+
679
+
For more information on configuration, see the following resources:
680
+
681
+
*<xref:fundamentals/configuration/index>
682
+
*<xref:blazor/fundamentals/configuration>
683
+
541
684
## Redirect to the home page on logout
542
685
543
686
The `LogInOrOut` component (`Layout/LogInOrOut.razor`) sets a hidden field for the return URL (`ReturnUrl`) to the current URL (`currentURL`). When the user signs out of the app, the identity provider returns the user to the page from which they logged out. If the user logs out from a secure page, they're returned to the same secure page and sent back through the authentication process. This authentication flow is reasonable when users need to change accounts regularly.
0 commit comments