Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbod committed Mar 24, 2024
1 parent bd196e4 commit d4080cd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions AspNetCoreSelectTenant/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public IndexModel(TenantProvider tenantProvider, TenantProviderCache tenantProvi
public string TenantId { get; set; } = string.Empty;

[BindProperty]
public List<string> RolesInTenant { get; set; } = new List<string>();
public List<string> RolesInTenant { get; set; } = [];

[BindProperty]
public string AppTenantName { get; set; } = string.Empty;

[BindProperty]
public List<SelectListItem> AvailableAppTenants { get; set; } = new List<SelectListItem>();
public List<SelectListItem> AvailableAppTenants { get; set; } = [];

public async Task OnGetAsync()
{
Expand Down
4 changes: 3 additions & 1 deletion AspNetCoreSelectTenant/Pages/SwitchTenant.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public async Task OnGetAsync()
RolesInTenant.Add(role.Value);
}

TenantId = HttpContext.User.FindFirstValue("http://schemas.microsoft.com/identity/claims/tenantid");
var tid = HttpContext.User.FindFirstValue("http://schemas.microsoft.com/identity/claims/tenantid");

if (tid != null) TenantId = tid;
}
}

Expand Down
9 changes: 5 additions & 4 deletions AspNetCoreSelectTenant/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@
services.AddRazorPages().AddMvcOptions(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
// Eanble to force tenant restrictions
.AddRequirements(new[] { new TenantRequirement() })
.Build();
.RequireAuthenticatedUser()
// Eanble to force tenant restrictions
.AddRequirements(new[] { new TenantRequirement() })
.Build();

options.Filters.Add(new AuthorizeFilter(policy));
}).AddMicrosoftIdentityUI();

Expand Down
5 changes: 4 additions & 1 deletion AspNetCoreSelectTenant/Tenants/TenantAdminHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public class TenantAdminHandler : AuthorizationHandler<TenantAdminRequirement>

public TenantAdminHandler(IConfiguration configuration)
{
tenantHomeId = configuration["AdminHomeTenant"];
var tid = configuration["AdminHomeTenant"]
?? throw new Exception("AdminHomeTenant configuration not set");

tenantHomeId = tid;
}

protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, TenantAdminRequirement requirement)
Expand Down

0 comments on commit d4080cd

Please sign in to comment.