Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between UseCookieAuthentication and UseIdentity?

In ASP.NET Core Startup in Configure method when you are configuring piplelines you can use UseIdentity from ASP.NET Core Identity or you can use UseCookieAuthentication. Both of them provide cookie based authentication.

I want to know what is their difference. Is UseIdentity uses UseCookieAuthentication internally? What are advantages and disadvantages of one over another?

Thanks for your explanations.

like image 628
Afshar Mohebi Avatar asked Dec 19 '22 10:12

Afshar Mohebi


1 Answers

From the docs which can be found here and here.

Cookie Authentication Middleware:

ASP.NET Core provides cookie middleware which serializes a user principal into an encrypted cookie and then, on subsequent requests, validates the cookie, recreates the principal and assigns it to the User property on HttpContext. If you want to provide your own login screens and user databases you can use the cookie middleware as a standalone feature.

Identity:

ASP.NET Core Identity is a membership system which allows you to add login functionality to your application. Users can create an account and login with a user name and password or they can use an external login providers such as Facebook, Google, Microsoft Account, Twitter and more.

In short Identity builds on just local authentication and provides the ability to perform external authentication as well as baked in solutions for provisioning user accounts.

The pros and cons of each differ depending on your business and both have their own place which I find is usually determine on a case by case basis.

The inner workings for Identity can be found on the github page here.

like image 168
LugTread Avatar answered Apr 18 '23 01:04

LugTread