0

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?

  • which middleware do you need this for Azure ADb2C ? – Abhay Dhar Jul 15 at 16:23
  • Yes, we need it for Azure Ad b2c – Hos Jul 16 at 5:12
  • Ok , once you plugged in your middleware , does the above code not work ? – Abhay Dhar Jul 16 at 9:15
  • Where do I plug it in? The Sitecore Owin .dll's already add CookieAuthentication, so I would guess I have to overwrite that somehow – Hos Jul 16 at 11:43
1

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));

        }
| improve this answer | |
  • Thank you for the suggestion - that is exactly what I want to do. When I try the above code, I get the dreaded "Error: Unsuccessful login with external provider" when trying to login to Sitecore or when browsing the enduser website.Any idea how to solve that? – Hos Jul 17 at 10:26
  • ok , maybe you could put a debug breakpoint to check where the error occurs in the file. Pl edit the question and add the complete code.cs file for better understanding. Also , while testing test the login in multiple browsers/incognito mode , it could be due to stored cookies as well – Abhay Dhar Jul 17 at 17:41
  • For some reason, the original code I posted worked all of a sudden. Maybe it was due to old cookies or similar as you suggested. I can accept your answer as the solution even though it was the code I originally posted, that ended up workin for me. Thanks for your input! – Hos Jul 24 at 10:15
  • glad , it worked out for ya. – Abhay Dhar Jul 24 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.