Hi all!
I wanted to post to the forums here and see if anyone has been successful at using Blazor Authentication/Authorization with Active Directory? (Not Azure Active Directory) this is an on-prem Active Directory.
Here is my scenario:
Here is an example:
I have been looking at this for 2 weeks and I cannot find a good example. Does anyone out there have something similar?
I am also VERY OPEN to other suggestions on how to do this through Active Directory. I have many clients that only use an on-prem Active Directory for application authentication and authorization.
Thank you and I appreciate any and all suggestions and input!!!
Kind Regards,
Jason
|
@attribute [Authorize(Roles="user, admin")]
@if (items != null)
{
<SfMenu TValue="MenuItem">
<MenuItems>
@foreach(var item in items)
{
<MenuItem Text="@item.Text"></MenuItem>
}
</MenuItems>
</SfMenu>
}
@code{
private List<MenuData> items;
[CascadingParameter]
private Task<AuthenticationState> authenticationStateTask { get; set; }
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
var user = (await authenticationStateTask).User;
items = new List<MenuData>();
items.Add(new MenuData { Text = "Home" });
items.Add(new MenuData { Text = "Reports" });
if (user.IsInRole("user"))
{
items.Add(new MenuData { Text = "User" });
}
if (user.IsInRole("admin"))
{
items.Add(new MenuData { Text = "Adminstration" });
}
items.Add(new MenuData { Text = "Contact Us" });
}
public class MenuData
{
public string Text
{
get;
set;
}
}
} |