Skip to content

Commit 4cc8e81

Browse files
authored
Update README.md
1 parent 0547110 commit 4cc8e81

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

2-Call-OwnApi/README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ The relevant code for this sample is in the `Program.cs` file, in the `RunAsync(
265265

266266
### TodoList Web API Code
267267

268-
The relevant code for the Web API is on the `Startup.cs` class. We are using the method `AddMicrosoftWebApiAuthentication` to configure the Web API to authenticate using bearer tokens, validate them and protect the API from non authorized calls. These are the steps:
268+
The relevant code for the Web API is in the `Startup.cs` class. We are using the method `AddMicrosoftWebApiAuthentication` to configure the Web API to authenticate using bearer tokens, validate them and protect the API from non authorized calls. These are the steps:
269269

270270
1. Configuring the API to authenticate using bearer tokens
271271

@@ -284,11 +284,26 @@ The relevant code for the Web API is on the `Startup.cs` class. We are using the
284284

285285
2. Validating the tokens
286286

287-
The `AadIssuerValidator.GetIssuerValidator` method can be found in `Microsoft.Identity.Web` project.
287+
As a result of the above `AddMicrosoftWebApiAuthentication` method, some audience and issuer validation is set up. More information can be found in [Microsoft Identity Web](https://github.com/AzureAD/microsoft-identity-web) project.
288288
289289
```CSharp
290-
options.TokenValidationParameters.ValidAudiences = new string[] { options.Audience, $"api://{options.Audience}" };
291-
options.TokenValidationParameters.IssuerValidator = AadIssuerValidator.GetIssuerValidator(options.Authority).Validate;
290+
if (options.TokenValidationParameters.AudienceValidator == null
291+
&& options.TokenValidationParameters.ValidAudience == null
292+
&& options.TokenValidationParameters.ValidAudiences == null)
293+
{
294+
RegisterValidAudience registerAudience = new RegisterValidAudience();
295+
registerAudience.RegisterAudienceValidation(
296+
options.TokenValidationParameters,
297+
microsoftIdentityOptions.Value);
298+
}
299+
300+
// If the developer registered an IssuerValidator, do not overwrite it
301+
if (options.TokenValidationParameters.IssuerValidator == null)
302+
{
303+
// Instead of using the default validation (validating against a single tenant, as we do in line of business apps),
304+
// we inject our own multi-tenant validation logic (which even accepts both v1.0 and v2.0 tokens)
305+
options.TokenValidationParameters.IssuerValidator = AadIssuerValidator.GetIssuerValidator(options.Authority).Validate;
306+
}
292307
```
293308

294309
3. Protecting the Web API

0 commit comments

Comments
 (0)