Installation
Microsoft.Owin.Host.SystemWeb
Identity.core
Microsoft.Owin.Security.Cookies
In is Startup.cs make the following changes
Public Partial classStartup { Public voidConfiguration (Iappbuilder app) {Configureauth (APP); } Public voidConfigureauth (Iappbuilder app) {//Configure The DB context, User Manager and Signin manager to use a single instance per request//app. Createperowincontext (applicationdbcontext.create); //app. Createperowincontext<applicationusermanager> (applicationusermanager.create); //app. Createperowincontext<applicationsigninmanager> (applicationsigninmanager.create); //Enable the application to use a cookie to store information for the signed in user//and to use a cookie to temporarily store information about a user logging in with a third party login provider //Configure the sign in cookieApp. Usecookieauthentication (Newcookieauthenticationoptions {AuthenticationType=Defaultauthenticationtypes.applicationcookie, Loginpath=NewPathString ("/home/index")//,, Cookiesecure=Cookiesecureoption.never//Provider = new Cookieauthenticationprovider//{ // //enables the application to validate the security stamp when the user logs in. // //This is a security feature which are used when you change a password or add an external login to your account. //onvalidateidentity = Securitystampvalidator.onvalidateidentity<applicationusermanager, ApplicationUser> ( //validateInterval:TimeSpan.FromMinutes (+),//regenerateidentity: (manager, user) = user. Generateuseridentityasync (manager))//} }); //app. Useexternalsignincookie (Defaultauthenticationtypes.externalcookie); //enables the application to temporarily store user information when they is verifying the second factor in the TWO-FA ctor authentication process. //app. Usetwofactorsignincookie (Defaultauthenticationtypes.twofactorcookie, Timespan.fromminutes (5)); //enables the application to remember the second login verification factor such as phone or email. //Once You check this option, your second step of verification during the login process would be remembered on the Devic e where you are logged in from. //This was similar to the rememberme option when you log in. //app. Usetwofactorrememberbrowsercookie (Defaultauthenticationtypes.twofactorrememberbrowsercookie); //uncomment the following lines to enable logging on with third party login providers//app. Usemicrosoftaccountauthentication (//clientId: "",//Clientsecret: ""); //app. Usetwitterauthentication (//Consumerkey: "",//Consumersecret: ""); //app. Usefacebookauthentication (//appId: "",//Appsecret: ""); //app. Usegoogleauthentication (New Googleoauth2authenticationoptions ()//{ //ClientId = "",//Clientsecret = ""//}); } }
Login Authentication Code
Claimsidentity ci =Newclaimsidentity (Defaultauthenticationtypes.applicationcookie); Ci. Addclaim (NewClaim (Claimtypes.name,"Brock") ); Ci. Addclaim (NewClaim (Claimtypes.role,"Admin") ); Ci. Addclaim (NewClaim (Claimtypes.email,"[email protected]"));//var id = new Claimsidentity (CI, Defaultauthenticationtypes.applicationcookie, Claimtypes.name, claimtypes.role);varCTX =Httpcontext.getowincontext ();varAuthenticationManager =CTX. Authentication;authenticationmanager.signin (NewAuthenticationproperties () {ispersistent =true}, CI);returnRedirecttoaction ("Test1");//return View ();
ASP. NET MVC claimsidentity Authorization Study (or Beta bug)