How to implement custom authorization for blazor server app using azure ad for authentication

I had to redo this video because of poor audio quality in the first one.
In this video I create a database containing three tables to store Azure AD Users and their roles.

Next I create a Data Service for the database inside my Blazor Server application.
Next I modify AccountController class by injecting the DataService into it.

Next I create a private method GetUserRolesAsync() which fetches user role from the database.
This method is then called inside CurrentUser() method.

Next I add authorize attribute to the top of pages I want to restrict access to.

Next I use authorizeview tag to group Navigation Menu Items I want to restrict access to.
Finally, I run the application to check if everything works well.

Source code can be pulled from GitHub - benjaminsqlserver/CustomAuthorizationForAzureAD

1 Like