/// <summary>
        /// Configures the application authentication.
        /// </summary>
        public void Configuration(IAppBuilder app)
        {
            // Register Kentico Membership identity implementation
            app.CreatePerOwinContext(() => KenticoUserManager.Initialize(app, new KenticoUserManager(new KenticoUserStore(SiteContext.CurrentSiteName))));
            app.CreatePerOwinContext <KenticoSignInManager>(KenticoSignInManager.Create);

            // Configure the sign in cookie
            UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath          = new PathString("/"),
                Provider           = new CookieAuthenticationProvider
                {
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <KenticoUserManager, User, int>(
                        // Sets the interval after which the validity of the user's security stamp is checked
                        validateInterval: TimeSpan.FromMinutes(1),
                        regenerateIdentityCallback: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie),
                        getUserIdCallback: ((claimsIdentity) => int.Parse(claimsIdentity.GetUserId()))),
                    // Redirect to logon page with return url
                    OnApplyRedirect = context => context.Response.Redirect(urlHelper.Action("Login", "Account") + new Uri(context.RedirectUri).Query)
                },
                ExpireTimeSpan    = TimeSpan.FromDays(14),
                SlidingExpiration = true,
                CookieName        = AUTHENTICATION_COOKIE_NAME
            });

            // Register the authentication cookie in the Kentico application and set its cookie level.
            // This will ensure that the authentication cookie will not be removed when a user revokes the tracking consent.
            CookieHelper.RegisterCookie(AUTHENTICATION_COOKIE_NAME, CookieLevel.Essential);
        }
        public void Configuration(IAppBuilder app)
        {
            // Registers the Kentico.Membership identity implementation
            app.CreatePerOwinContext(() => KenticoUserManager.Initialize(app, new KenticoUserManager(new KenticoUserStore(SiteContext.CurrentSiteName))));
            app.CreatePerOwinContext <KenticoSignInManager>(KenticoSignInManager.Create);

            // Configures the authentication cookie
            UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                // Fill in the name of your sign-in action and controller
                LoginPath = new PathString(urlHelper.Action("SignIn", "Account")),
                Provider  = new CookieAuthenticationProvider
                {
                    // Sets the return URL for the sign-in page redirect (fill in the name of your sign-in action and controller)
                    OnApplyRedirect = context => context.Response.Redirect(urlHelper.Action("SignIn", "Account")
                                                                           + new Uri(context.RedirectUri).Query)
                }
            });

            // Registers the authentication cookie with the 'Essential' cookie level
            // Ensures that the cookie is preserved when changing a visitor's allowed cookie level below 'Visitor'
            CookieHelper.RegisterCookie(OWIN_COOKIE_PREFIX + DefaultAuthenticationTypes.ApplicationCookie, CookieLevel.Essential);
        }
Esempio n. 3
0
        public void Configuration(IAppBuilder app)
        {
            // Registers the Kentico.Membership identity implementation
            app.CreatePerOwinContext(() => KenticoUserManager.Initialize(app, new KenticoUserManager(new KenticoUserStore(SiteContext.CurrentSiteName))));
            app.CreatePerOwinContext <KenticoSignInManager>(KenticoSignInManager.Create);

            // Configures the authentication cookie
            UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                // Fill in the name of your sign-in action and controller
                LoginPath = new PathString(urlHelper.Action("SignIn", "Account")),
                Provider  = new CookieAuthenticationProvider
                {
                    // Sets the return URL for the sign-in page redirect (fill in the name of your sign-in action and controller)
                    OnApplyRedirect = context => context.Response.Redirect(urlHelper.Action("SignIn", "Account")
                                                                           + new Uri(context.RedirectUri).Query)
                }
            });

            // Registers the authentication cookie with the 'Essential' cookie level
            // Ensures that the cookie is preserved when changing a visitor's allowed cookie level below 'Visitor'
            CookieHelper.RegisterCookie(OWIN_COOKIE_PREFIX + DefaultAuthenticationTypes.ApplicationCookie, CookieLevel.Essential);

            // Uses a cookie to temporarily store information about users signing in via external authentication services
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // Registers a WS-Federation authentication service
            app.UseWsFederationAuthentication(
                new WsFederationAuthenticationOptions
            {
                // Set any properties required by your authentication service
                MetadataAddress = "placeholder",     // Fill in the address of your service's WS-Federation metadata
                Wtrealm         = "",
                // When using external services, Passive authentication mode may help avoid redirect loops for 401 responses
                AuthenticationMode = AuthenticationMode.Passive
            });

            // Registers an OpenID Connect authentication service
            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
            {
                // Set any properties required by your authentication service
                ClientId           = "placeholder",
                ClientSecret       = "placeholder",
                Authority          = "https://placeholder",
                AuthenticationMode = AuthenticationMode.Passive
            });

            // Registers the Facebook authentication service
            app.UseFacebookAuthentication(
                new FacebookAuthenticationOptions
            {
                // Fill in the application ID and secret of your Facebook authentication application
                AppId     = "placeholder",
                AppSecret = "placeholder"
            });

            // Registers the Google authentication service
            app.UseGoogleAuthentication(
                new GoogleOAuth2AuthenticationOptions
            {
                // Fill in the client ID and secret of your Google authentication application
                ClientId     = "placeholder",
                ClientSecret = "placeholder"
            });
        }