public void Configuration(IAppBuilder app)
        {
            app.AddCmsAspNetIdentity <ApplicationUser>(new ApplicationOptions()
            {
                ConnectionStringName = "EPiServerDB"
            });

            // 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("/util/login.aspx"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager <ApplicationUser>, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => manager.GenerateUserIdentityAsync(user)),
                    OnApplyRedirect = (context =>
                    {
                        if (!ContentApiHelper.IsContentApiRequest(context.Request.Uri))
                        {
                            context.Response.Redirect(context.RedirectUri);
                        }
                    }),
                    OnResponseSignOut = (context => context.Response.Redirect(UrlResolver.Current.GetUrl(ContentReference.StartPage))),
                },
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            app.UseContentApiIdentityOAuthAuthorization <ApplicationUserManager <ApplicationUser>, ApplicationUser>(new ContentApiOAuthOptions()
            {
                RequireSsl = false,
            });
        }
Exemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            app.AddCmsAspNetIdentity <SiteUser>(new ApplicationOptions
            {
                ConnectionStringName = _connectionStringHandler.Commerce.Name
            });

            // 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("/Login"),
                Provider           = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager <SiteUser>, SiteUser>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentity: (manager, user) => manager.GenerateUserIdentityAsync(user)),
                    OnApplyRedirect = (context =>
                    {
                        if (!ContentApiHelper.IsContentApiRequest(context.Request.Uri))
                        {
                            context.Response.Redirect(context.RedirectUri);
                        }
                    }),
                    OnResponseSignOut = (context => context.Response.Redirect(UrlResolver.Current.GetUrl(ContentReference.StartPage))),
                },
            });

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            app.UseContentApiIdentityOAuthAuthorization <ApplicationUserManager <SiteUser>, SiteUser>(new ContentApiOAuthOptions()
            {
                RequireSsl = false,
            });

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor 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 will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

#if GOOGLE_ACCOUNT_LOGIN_FEATURE
#if (FACEBOOK_ACCOUNT_LOGIN_FEATURE || TWITTER_ACCOUNT_LOGIN_FEATURE || MICROSOFT_ACCOUNT_LOGIN_FEATURE)
#error Can not combine the Google authentication with another one.
#endif
            EnableGoogleAccountLogin(app);
#endif

#if FACEBOOK_ACCOUNT_LOGIN_FEATURE
#if (GOOGLE_ACCOUNT_LOGIN_FEATURE || TWITTER_ACCOUNT_LOGIN_FEATURE || MICROSOFT_ACCOUNT_LOGIN_FEATURE)
#error Can not combine the Facebook authentication with another one.
#endif
            EnableFacebookAccountLogin(app);
#endif

#if TWITTER_ACCOUNT_LOGIN_FEATURE
#if (GOOGLE_ACCOUNT_LOGIN_FEATURE || FACEBOOK_ACCOUNT_LOGIN_FEATURE || MICROSOFT_ACCOUNT_LOGIN_FEATURE)
#error Can not combine the Twitter authentication with another one.
#endif
            EnableTwitterAccountLogin(app);
#endif

#if MICROSOFT_ACCOUNT_LOGIN_FEATURE
#if (GOOGLE_ACCOUNT_LOGIN_FEATURE || FACEBOOK_ACCOUNT_LOGIN_FEATURE || TWITTER_ACCOUNT_LOGIN_FEATURE)
#error Can not combine the Microsoft authentication with another one.
#endif
            EnableMicrosoftAccountLogin(app);
#endif
        }