Extend asp.net mvc 5 identity

3

I have to set up a login system and that this system can be reused in two mvc projects

The model (according to the architecture) is as follows:

  • User : usu, password, email Confirmed, etc.

  • Client : userId, email, etc.

  • Employee : userId, email, etc.

In turn, the model has other tables for security:

  • Permission_user : user_id, permission_id

  • Permission : permissionId, desc

  • Rol_Permiso : rolId, permissionId

  • Role : rolId, desc

  • User_Rol : userId, rolId

My question is is it advisable to extend the asp.net mvc5 identity or is it preferable to use my own login system?

Greetings

    
asked by Mauro Petrini 04.02.2016 в 06:35
source

2 answers

2

In my opinion I would say categorically if, using ASP.NET Identity will bring you many advantages, ignoring the cryptographic tasks and saving you work. In addition, ASP.NET Identity is ready to be extended because, in a simple way you can change from the type of identifiers to use your own entities of usuarios , roles , ...

I think that in your case you only need to put it in common, add an authorization system and link the entities of usuarios with those of clientes and empleados

A simple way to do this would be to create a Biblioteca de clases project and move the ASP.NET Identity elements that are included, by default, in the MVC project ( ApplicationUser , ApplicationDbContext , ApplicationUserManager , ...).

Afterwards, you would add the necessary elements to manage the authorization (entities to define the permissions, service to manage the authorization, ...)

In my opinion, the association between usuarios and clientes and empleados would not include it in the common project because it could be useful for more projects in which you do not have these entities.

And finally, if you pack this project in a NuGet package, you could, in a simple way, add authentication and authorization to all your projects.

In this CodeProject article " ASP.NET Identity with webforms " you can see the flesibility of ASP.NET Identity that you can even "click" on a WebForms project

    
answered by 04.02.2016 в 08:14
1

Identity uses Entity Framework to implement the persistence of the entities it defines, which allows us to apply inheritance when extending its functionality.

Extending ASP.net Identity in an ASP.net MVC 5 application

You can start with something simple, for example, add a property to the user

public class ApplicationUser : IdentityUser
{
    public string Email { get; set; } 
}

The class inherits from IdentityUser which defines the structure of the table AspNetUser

ASP.NET MVC 5: Extending ASP.NET Identity 2.0 Roles and Implementation of Role Based Authorization

But you can also extend the other objects defined in the Identity model, such as the role, by adding a new property.

public class ApplicationRole : IdentityRole
{
    public virtual string Description { get; set; }
}

As you will understand it is only a matter of applying inheritance, but because it is EF you can also define the context to customize how to map these new properties to the db fields

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {

    }
}

Another advantage that you get when using EF is that you can apply migrations to update the data structure you have defined.

    
answered by 04.02.2016 в 09:37