TransWikia.com

How to modify CookieAuthentication options in Sitecore 9?

Sitecore Asked on August 23, 2021

In Sitecore 9.2, we would like to change some of the CookieAuthenticationOptions, that are used for Authentication.

This is the code we would use:

args.App.UseCookieAuthentication(
    new CookieAuthenticationOptions
    {
        CookiePath = "/",
#if !DEBUG
        CookieDomain = ".customdomain.com",
#endif
        TicketDataFormat = new TicketDataFormat(new MachineKeyProtector()),
        LoginPath = new Microsoft.Owin.PathString("/auth/sso/login"),
        LogoutPath = new Microsoft.Owin.PathString("/auth/sso/logout"),
    },

    // It seems there are issues with the ordering of Forms Authentication (Sitecore) and this OWIN middleware. Therefore we run this middleware 
    // at the IIS pipeline stage right after Forms Authentication (Authenticate stage) to ensure the order is deterministic.
    PipelineStage.PostAuthenticate);

How and where would I hook into the Owin pipeline in Sitecore 9.2 to achieve this?

One Answer

Not sure if I understood your question correctly , but every middlewware can inject or implement its own cookieauthentication options. see below code and this questions - How to get Sitecore.Context.User after redirect from Azure ADb2c login?

protected override void ProcessCore(IdentityProvidersArgs args)
        {
            // Required for Azure webapps, as by default they force TLS 1.2 and this project attempts 1.0
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            Assert.ArgumentNotNull(args, nameof(args));
            var identityProvider = this.GetIdentityProvider();
            var authenticationType = this.GetAuthenticationType();

            args.App.UseCookieAuthentication(new CookieAuthenticationOptions());
            args.App.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(EditProfilePolicyId));
            args.App.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(ResetPasswordPolicyId));
            args.App.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(SignUpPolicyId));
            args.App.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(SignInPolicyId));

        }

Correct answer by Abhay Dhar on August 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP