public static AuthorizationPolicyBuilder RequireAuthenticatedUserExtended( this AuthorizationPolicyBuilder builder, IServiceCollection services, SecurityOptions options) { var requireAuthenticatedUser = new DenyAnonymousAuthorizationRequirementExtended(options); services.AddSingleton <IAuthorizationHandler>(requireAuthenticatedUser); builder.AddRequirements(requireAuthenticatedUser); return(builder); }
public static AuthorizationPolicyBuilder RequireAuthenticatedUserExtended( this AuthorizationPolicyBuilder builder, IServiceCollection services) { var serviceProvider = services.BuildServiceProvider(); var security = serviceProvider.GetRequiredService <IValidOptionsMonitor <SecurityOptions> >(); var superUser = serviceProvider.GetRequiredService <IValidOptionsMonitor <SuperUserOptions> >(); var requireAuthenticatedUser = new DenyAnonymousAuthorizationRequirementExtended(security, superUser); services.AddSingleton <IAuthorizationHandler>(requireAuthenticatedUser); builder.AddRequirements(requireAuthenticatedUser); return(builder); }