Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIdentity, IPrincipal or IUser: what's the difference?

I'm trying to implement simple role based authentication + authorization in an MVC5 application, but I'm getting some headache trying to understand all the parts involved in Identity framework

I'm reading several tutorials and guides, but I stil haven't a clear idea.

In particular: which is the difference among IIdentity, IPrincipal or IUser interfaces? Which of them should I implement?

like image 736
davioooh Avatar asked Jul 17 '15 13:07

davioooh


People also ask

What is the meaning of IISER?

2. Indian Institute of Science Education and Research (IISER), Pune. The Indian Institute of Science Education and Research Pune is a premier institute dedicated to research and teaching in the basic sciences was established in 2006.

What is the use of IISER?

IISERs are autonomous institutes that award their own masters and doctoral degrees to students. Declared 'Institutes of National Importance' by the Parliament in 2012, IISERs offer courses such as BS-MS, integrated PhD and PhD to aspirants.

What is difference between IISER and IISc?

Seven IISER were established recently with the goal of providing quality education in pure science. IISERs were established with the expectations that they would reach global standards in the field of basic sciences and offer intensive research like IISc. IISERs offer courses such as BS-MS, integrated Ph. D., and Ph.

What is difference between IISER and IIT?

The difference between IISERs and IITs is the student crowd. Since IISER is more research-oriented, you will get to meet people who are genuinely interested in research.


1 Answers

'IPrincipal' is a .Net framework's interface:

public interface IPrincipal {
    // Retrieve the identity object
    IIdentity Identity { get; }

    // Perform a check for a specific role
    bool IsInRole (string role);
}

This interface defines the basic functionality of logged in user. Object implementing this interface represents the security context under which your code is running. You can get different flavors of IPrincipal in .Net: ClaimsPrincipal, WindowsPrincipal and others - all depends on the framework you are using. If you are working with Asp.Net Identity framework, you'll be dealing with ClaimsPrincipal. Usually you don't need to implement this interface.

IIdentity represents user's permissions. For Asp.Net Identity framework you'll be dealing with ClaimsIdentity. Again, this is something you don't need to implement.

Here is more documentation about the IPrincipal and IIDentity.

IUser is part of Asp.Net Identity framework. If you are using Entity Framework part of Identity, you'll be provided with IdentityUser class that you can inherit and extend. This is a model for you to implement.

Basically IdentityUser is a POCO that is preserved into a database. And when user is logged in, information from IdentityUser will be transformed into ClaimsPrincipal and ClaimsIdentity by the framework. And when you access HttpContext.Current.User you will be given ClaimsPrincipal.

Hope this clears things up for you.

like image 60
trailmax Avatar answered Sep 22 '22 15:09

trailmax