Skip to content

Commit 6f5dbe7

Browse files
authored
Scope source for the request transformer (#36302)
1 parent 7d71561 commit 6f5dbe7

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

.github/workflows/blazor-hybrid-issue-processing.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
issue_number: context.issue.number,
1818
owner: context.repo.owner,
1919
repo: context.repo.repo,
20-
body: `### 🧟💀 ***Happy Halloween!!*** 🎃🧛
20+
body: `### 🦃 ***Happy Thanksgiving!*** 🍽️
2121
22-
A green dinosaur 🦖 will be along shortly to assist. *Stand-by ........*`
22+
*Stand-by!* A green dinosaur 🦖 will be along shortly to assist.`
2323
})
2424
await github.rest.issues.addLabels({
2525
issue_number: context.issue.number,

.github/workflows/blazor-issue-processing.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ jobs:
2323
issue_number: context.issue.number,
2424
owner: context.repo.owner,
2525
repo: context.repo.repo,
26-
body: `### 🧟💀 ***Happy Halloween!!*** 🎃🧛
26+
body: `### 🦃 ***Happy Thanksgiving!*** 🍽️
2727
28-
*Stand-by!* ... A green dinosaur 🦖 will be along shortly to assist.`
28+
*Stand-by!* A green dinosaur 🦖 will be along shortly to assist.`
2929
})
3030
await github.rest.issues.addLabels({
3131
issue_number: context.issue.number,

aspnetcore/blazor/security/blazor-web-app-with-entra.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
385385
.AddDistributedTokenCaches();
386386
```
387387

388+
Provide the same downstream API scope to the request transformer:
389+
390+
```csharp
391+
List<string> scopes = [ "{APP ID URI}/Weather.Get" ];
392+
```
393+
388394
Placeholders in the preceding configuration:
389395

390396
* `{CLIENT ID (BLAZOR APP)}`: The application (client) ID.
@@ -412,11 +418,18 @@ builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
412418
.AddDownstreamApi("DownstreamApi", configOptions =>
413419
{
414420
configOptions.BaseUrl = "https://localhost:7277";
415-
configOptions.Scopes = [ "api://11112222-bbbb-3333-cccc-4444dddd5555/Weather.Get" ];
421+
configOptions.Scopes =
422+
[ "api://11112222-bbbb-3333-cccc-4444dddd5555/Weather.Get" ];
416423
})
417424
.AddDistributedTokenCaches();
418425
```
419426

427+
Example:
428+
429+
```csharp
430+
List<string> scopes = [ "api://11112222-bbbb-3333-cccc-4444dddd5555/Weather.Get" ];
431+
```
432+
420433
:::zone-end
421434

422435
> [!WARNING]
@@ -642,6 +655,15 @@ builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
642655
.AddDistributedTokenCaches();
643656
```
644657

658+
```diff
659+
- List<string> scopes = ["{APP ID URI}/Weather.Get"];
660+
- var accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(scopes);
661+
+ var configuration = transformContext.HttpContext.RequestServices.GetRequiredService<IConfiguration>();
662+
+ var scopes = configuration.GetSection("DownstreamApi:Scopes").Get<IEnumerable<string>>();
663+
+ var accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(scopes ??
664+
+ throw new InvalidOperationException("No downstream API scopes!"));
665+
```
666+
645667
> [!NOTE]
646668
> Production apps should use a production distributed token cache provider. Otherwise, the app may have poor performance in some scenarios. For more information, see the [Use a production distributed token cache provider](#use-a-production-distributed-token-cache-provider) section.
647669

0 commit comments

Comments
 (0)