ASP. NET identity (processing identity data store) and Owin host (implement Katana authentication authorization) Principle summary

Source: Internet
Author: User

The ASP. NET Identity is introduced in 4.5, support Clamis (declaration) Style login "authentication and authorization separate mode", combined with Owin can realize the function of cookie encryption.

1.asp.net Identity Architecture Framework Description

At the top is the middle of the integration implementation (Identity.entityframwork---it is how the user data is stored, and this layer is the implementation layer of the EF-based storage implemented by Microsoft itself. Several identity.core can be rewritten directly to implement different storage methods.
Among them, Iuserstore Userstore is the implementation of some data manipulation methods for user objects in storage, such as password authentication method or find User method.
Identityuser inherits from the underlying iuser, and can extend the user's field data and so on.

Finally, Iuserstore is used as the parameter instantiation Usermanager to do the related business logic operation of the user.

2, Owin is Microsoft defines a set of alternatives to the IIS pipeline processing, so that the request and response context content operations and appapliction operations are managed to Owin processing.

In conjunction with the implementation of the declarative (Claims) login As an example to explain Owin, the following is the login code

//1. Get user objects with ASP.varuser =awaitUsermanager.findasync ("UserName","Password");//2. Using the ASP. Claimsidentity (Identity object, which contains the user's basic information)varIdentity =awaitusermanager.createidentityasync (user, defaultauthenticationtypes.applicationcookie);//3. The identity object obtained above takes advantage of Owin's pipeline processing method to log in, encrypt write to read Coocie and process and manage Claimsprincipal object (is 2 encapsulation, this object is assigned to Http--> Crrentuser) Authenticationmanager.signin (NewAuthenticationproperties () {ispersistent =true}, identity);

Owin's open source implementation is katana, achieving four

    • Host: The process that hosts our application, or the host, which can be IIS, the program we write ourselves, and so on. Primarily used to start, load Owin components, and reasonably close them
    • Server: This server is used to expose the TCP port, maintain the dictionary data we mentioned above, and then handle HTTP requests through Owin management
    • Middleware: This middleware is the component used to process requests in the Owin pipeline, and you can think of it as a custom httpmodule that will be registered with the Owin pipeline to process the HTTP request
    • Application: It's best to understand that the app we've developed, or the website .

To log in as an example, the implementation of Owin must have a declaration entry Starup (new MVC can be seen in the AppStart folder)

 public  partial  class   startup{ public  void   Configureauth (Iappbuilder app) { //  Configuring middleware components options,  Middleware is to handle different businesses such as the following Cookieauthenticationmiddleware, can refer to him from the definition of middleware , can refer to open source Owin--catana code  
//This is the process of using Coocie landing middleware, is the Iappbuilder extension method        App. Usecookieauthentication (new  cookieauthenticationoptions        {            =  Defaultauthenticationtypes.applicationcookie,            new pathstring ("/account/login  "),            = cookiesecureoption.never,        });}    }

This is the implementation of the on-site middleware extension method

 public  static  Iappbuilder     Usecookieauthentication (this   Iappbuilder app, Cookieauthenticationoptions options) { if  (App = = null   throw  new  ArgumentNullException ( app      ); } app. Use ( typeof   ( Cookieauthenticationmiddleware), apps, options); Register the component in the Owin pipeline,--   cookieauthenticationmiddleware--  The component is an operation of the cryptographic Coocie 
return app;}

ASP. NET identity (processing identity data store) and Owin host (implement Katana authentication authorization) Principle summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.