Implement authentication with different roles

Viewed 46

I am both an apprentice and a student, and I have to develop a web application for school, with ASP.NET MVC (.NET 6.0).

Though I am working with ASP.NET MVC at work and I also developed a small MVC app on myself, I am very new to the use of authentication (Identity, claims... are yet unknown territory). We receive no help from teachers for this project, so I am asking for you kind help and clarification.

The overall question is: how can I implement authentication with 3 models corresponding to 3 roles?

Context

At the end of an apprenticeship year, each student has an oral presentation, attended by two teachers and the student's apprenticeship manager (from the company). The application goal is to provide a way for tutor teachers and apprenticeship managers to give the dates they are available on for the oral and then find a date that suits them all. The calendar will finally be known from them and from students.

Requirements

Teachers and apprenticeship managers should have accounts that will first be created by admins. Students don't need accounts, though they have personal records created by admins.

There should be a controller for students, one for apprenticeship managers, and one for teachers (to list them, view details, create and delete).

Questions

Since there will be 3 types of users (manager, teacher, admin), should I use claims? Or roles? Should I make a custom IdentityUser?

I would like students, managers and teachers (maybe admins too) to have their own model (their own class in my Model directory), because for instance only a Manager instance would contain a School instance, and only a Teacher instance would contain a Specialty instance. But managers and teachers models should also be able to authenticate and thus to implement the Identity functionnality. How can I do that?

I am a bit overwhelmed by the documentation of Microsoft, which is very rich in information of all kind, but I struggle to link the pieces. That's why I am asking for your help: to find a direction. This is my first post on StackOverflow, I hope it is not too confused and imprecise. Thanks in advance for your help.

1 Answers

In my opinion, I suggest you shouldn't create a custom identity user. You could use role management inside the identity to check the user is teacher , admin or student.

Then you could create another dbmodel School instance, Specialty instance which will reference the identity user.

Then inside the view page, you could use role management to manage the access and then use the EF dbcontext to query the user's related information like School instance or Specialty instance(if this user contains them).

Related