Skip to content

Commit b6f735e

Browse files
authored
Merge pull request #107979 from PramodKumarHK89/patch-8
Add more clarity on the middleware configuration
2 parents 8dc7b55 + 691a179 commit b6f735e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

articles/active-directory/develop/scenario-web-api-call-api-app-configuration.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,28 @@ using Microsoft.Identity.Web;
126126
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
127127
.AddMicrosoftIdentityWebApi(Configuration, "AzureAd")
128128
.EnableTokenAcquisitionToCallDownstreamApi()
129-
.AddDownstreamWebApi("MyApi", Configuration.GetSection("GraphBeta"))
129+
.AddDownstreamWebApi("MyApi", Configuration.GetSection("MyApiScope"))
130130
.AddInMemoryTokenCaches();
131131
// ...
132132
```
133+
If the web app needs to call another API resource, repeat the `.AddDownstreamWebApi()` method with the relevant scope as shown in the following snippet:
134+
135+
```csharp
136+
using Microsoft.Identity.Web;
137+
138+
// ...
139+
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
140+
.AddMicrosoftIdentityWebApi(Configuration, "AzureAd")
141+
.EnableTokenAcquisitionToCallDownstreamApi()
142+
.AddDownstreamWebApi("MyApi", Configuration.GetSection("MyApiScope"))
143+
.AddDownstreamWebApi("MyApi2", Configuration.GetSection("MyApi2Scope"))
144+
.AddInMemoryTokenCaches();
145+
// ...
146+
```
147+
148+
Note that `.EnableTokenAcquisitionToCallDownstreamApi` is called without any parameter, which means that the access token will be acquired just in time as the controller requests the token by specifying the scope.
149+
150+
The scope can also be passed in when calling `.EnableTokenAcquisitionToCallDownstreamApi`, which would make the web app acquire the token during the initial user login itself. The token will then be pulled from the cache when controller requests it.
133151

134152
Similar to web apps, various token cache implementations can be chosen. For details, see [Microsoft identity web - Token cache serialization](https://aka.ms/ms-id-web/token-cache-serialization) on GitHub.
135153

0 commit comments

Comments
 (0)