active-directory-dotnet-native-aspnetcore-v2
active-directory-dotnet-native-aspnetcore-v2 copied to clipboard
protected web api with GetAadIssuerValidator
- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [ x] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)
I am using .NET 5.0 and trying to validate the issuer. Do we have any samples doing this? I have not figure out how to get the service provider (IServiceProvider) in order to call GetRequiredService,
MicrosoftIdentityIssuerValidatorFactory microsoftIdentityIssuerValidatorFactory =
**_serviceProvider**.GetRequiredService<MicrosoftIdentityIssuerValidatorFactory>();
options.TokenValidationParameters.IssuerValidator = microsoftIdentityIssuerValidatorFactory.GetAadIssuerValidator(options.Authority).Validate;
@jrmcdona IOptions has several generic overrides that can provide you the types you want by dependency injection
See: https://github.com/AzureAD/microsoft-identity-web/blob/fe47497f97f2956ac238cd18034666934cc9ec8d/src/Microsoft.Identity.Web/WebApiExtensions/MicrosoftIdentityWebApiAuthenticationBuilderExtensions.cs#L172-L173
// Change the authentication configuration to accommodate the Microsoft identity platform endpoint (v2.0).
builder.Services.AddOptions<JwtBearerOptions>(jwtBearerScheme)
.Configure<IServiceProvider, IOptionsMonitor<MicrosoftIdentityOptions>>((options, serviceProvider, microsoftIdentityOptionsMonitor) =>
{