active-directory-dotnet-native-aspnetcore-v2 icon indicating copy to clipboard operation
active-directory-dotnet-native-aspnetcore-v2 copied to clipboard

protected web api with GetAadIssuerValidator

Open jrmcdona opened this issue 4 years ago • 1 comments

- [ ] 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 avatar Mar 14 '21 20:03 jrmcdona

@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) =>
                {

jmprieur avatar Mar 15 '21 09:03 jmprieur