private async Task SignInAsync(PhiUser user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, await PhiUserHelpers.GenerateUserIdentityAsync(user, UserManager)); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Configure the db context and user manager to use a single instance per request app.CreatePerOwinContext(CreateContext); app.CreatePerOwinContext <PhiUserManager>(PhiUserManager.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 cookie app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <PhiUserManager, PhiUser>( validateInterval: TimeSpan.FromMinutes(20), regenerateIdentity: (manager, user) => PhiUserHelpers.GenerateUserIdentityAsync(user, manager)) } }); // Use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Enable the application to use bearer tokens to authenticate users app.UseOAuthBearerTokens(OAuthOptions); // Uncomment the following lines to enable logging in with third party login providers // HowTo's: http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); app.UseTwitterAuthentication( consumerKey: "qjFuMN5vQOYfvuPUIQwtyDIai", consumerSecret: "zvRkd9xims5EXJcZaevybjZL99nV5C4p3cLUEXhejqdZ0HTWl8"); app.UseFacebookAuthentication( appId: "1564578970427215", appSecret: "2e3d55f99733f2327f47edb3390c3bd6"); app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() { ClientId = "778525950974-00m0pukba75pcrrubisjf12civpo1u8v.apps.googleusercontent.com", ClientSecret = "bTEm0nbk55cjefmnvuK-98WC" }); }