Update how default auth policy is set in templates (#22884)

* Update how default auth policy is set in templates
* Respond to feedback from peer review
This commit is contained in:
Safia Abdalla 2020-06-15 20:27:33 -07:00 committed by GitHub
parent af0a3ed83c
commit b484680092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -116,12 +116,12 @@ namespace BlazorServerWeb_CSharp
#endif #endif
#if (OrganizationalAuth) #if (OrganizationalAuth)
services.AddControllersWithViews(options => services.AddControllersWithViews();
services.AddAuthorization(options =>
{ {
var policy = new AuthorizationPolicyBuilder() // By default, all incoming requests will be authorized according to the default policy
.RequireAuthenticatedUser() options.FallbackPolicy = options.DefaultPolicy;
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
}); });
#endif #endif

View File

@ -108,13 +108,12 @@ namespace Company.WebApplication1
.AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options)); .AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
#endif #endif
#if (OrganizationalAuth) #if (OrganizationalAuth)
services.AddControllersWithViews();
services.AddControllersWithViews(options => services.AddAuthorization(options =>
{ {
var policy = new AuthorizationPolicyBuilder() // By default, all incoming requests will be authorized according to the default policy
.RequireAuthenticatedUser() options.FallbackPolicy = options.DefaultPolicy;
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
}); });
#else #else
services.AddControllersWithViews(); services.AddControllersWithViews();