How do I ignore identity framework magic, just using Owin validated middleware to get the requirements I seek?

Source: Internet
Author: User
Tags httpcontext

The Owin middleware for something third-party login integration into your ASP. NET application is very cool, but I can't seem to figure out how to gouge out the new ID, which replaces the crappy membership API. I am not interested in insisting on the resulting claims and persisting in English and French based data, I just want to do this so I can apply it to my existing project account. I don't want to use the new numbering just to take advantage of these things. I've been browsing the code on CodePlex, but there's a whole bunch of static magic. Can you give me any advice?
This address:

--------------------------------------------------------------------------------------------------------------- ----------
1. Use the following code to set up the Owin security middleware:

App. Usecookieauthentication (Newcookieauthenticationoptions{AuthenticationType="Application", Authenticationmode=authenticationmode.passive, Loginpath=NewPathString ("/login"), Logoutpath=NewPathString ("/logout"), App. Setdefaultsigninasauthenticationtype ("External"); app. Usecookieauthentication (Newcookieauthenticationoptions{AuthenticationType="External", Authenticationmode=authenticationmode.passive, CookieName= Cookieauthenticationdefaults.cookieprefix +"External", Expiretimespan= Timespan.fromminutes (5), App. Usegoogleauthentication ();

The above code sets the application's cookie, external cookie and Google external login middleware. The external login middleware converts the login data to the identity and sets it as the middleware for external cookies. In your application, you need to get an external cookie identity and convert it to external login data, then you can use it to check your sample code below. Please use the application's cookie:

varauthentication =System.Web.HttpContext.Current.GetOwinContext (). authentication;varIdentity =NewClaimsidentity ("Application"); identity. Addclaim (NewClaim (,"<user name>") ); authentication. Authenticationresponsegrant=NewAuthenticationresponsegrant (Identity,Newauthenticationproperties () {ispersistent=false});

To obtain the application's cookie identity:

var  as claimsidentity;

To obtain an external cookie identity (Google):

var authentication = System.Web.HttpContext.Current.GetOwinContext (). authentication; var await authentication. Authenticateasync ("External"); var externalidentity = result. Identity;

Extract external login data from identity:

 Public StaticExternallogindata fromidentity (claimsidentity identity) {if(Identity = =NULL) {  return NULL; } Claim Providerkeyclaim=identity. FindFirst (Claimtypes.nameidentifier); if(Providerkeyclaim = =NULL||String.IsNullOrEmpty (Providerkeyclaim.issuer)||String.IsNullOrEmpty (Providerkeyclaim.value)) {  return NULL; } if(Providerkeyclaim.issuer = =claimsidentity.defaultissuer) {return NULL; } return NewExternallogindata {Loginprovider=Providerkeyclaim.issuer, Providerkey=Providerkeyclaim.value, UserName=identity. Findfirstvalue (};}

How do I ignore identity framework magic, just using Owin validated middleware to get the requirements I seek?

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: 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.