Sitecore.HabitatHome.Platform – A bug on Creative Exchange and Federated Authentication

[Updates]

08 Aug 2018 (08/08/2018) – it such a beautiful day ūüôā

I made a pull-request to Sitecore.HabitatHome.Platform repo. They’ve already merged into develop branch. This bug has been reported to SXA team and they said that it will be fixed in SXA 1.8.

Now you can use Creative Exchange to export the site or even the page correctly.

Please also note that the current versions are

Thanks @jeanfrancoislarente @ezlateva for review, suggest and merge my PR.

[End-of-Updates]


Recently, while playing with Sitecore.HabitatHome.Platform, I want to experiment with Creative Exchange which is an SXA feature, I faced with the issue while exporting a site and even a specific page. It exported only the link of “Object moved to” instead of the full HTML page. It only happens on the project which is built with SXA along with¬†Federated Authentication¬†(this is an approach of Sitecore.HabitatHome.Content).¬†

What is Creative Exchange?

If you’re not familiar with this feature, you should take a look onto Sitecore Document:

TL;DR;

Creative Exchange Live is an SXA feature that enables front-end developers to modify themes and other site content without having to import the files back into the site. Creative Exchange Live works with Gulp tasks that enable you to make changes to themes and other content and synchronize to the Sitecore environment immediately.

What is “Object moved to” issue?

After exporting the site or even a specific page by using Create Exchange whether zip file or Folder, we expected the full HTML will be exported but it’s only the link with caption “Object moved to”

Creative Exchange - Object moved to
Creative Exchange – Object moved to

If we inspect the link, it begins with the “sitecore/login” which means that it does not pass the authentication. After digging into the processors of Sitecore.XA.Feature.CreativeExchange by exploring on dotPeek (a tool of JetBrains), I found the way they got the HTML content, it simply makes a request within the authentication cookies. Seems there is no special, huh? By default, Sitecore uses Form Authentication with the default authentication cookie name is .ASPXAUTH¬†.

Creative Exchange - Form Authentication

But in our case, we’re using Federated Authentication (a.k.a Sitecore.Owin.Authentication), therefore the .ASPXAUTH¬†is not used. Instead, it has to use the cookie name – .AspNet.Cookies¬†(remember the “.” character).¬†

How to resolve the problem?

There are 2 ways to resolve this problem:

  • Solution No.1: Disabled Federated Authentication and switch back to Form Authentication.
  • Solution No.2:¬†this solution provides the elegant fix which is custom the processor in¬†ceExport.pageProcessing pipeline. The detail implementation in below

Solution No.1

This solution provides the simplest and fastest fix but it also does not use the implementation of Federated Authentication. Therefore I do not prefer this solution but in some situations, it can be acceptable, I think.

We have 2 following steps to apply this solution:

  1. Disabled Federated Authentication
    • Rename “Feature.Accounts.config” to “Feature.Accounts.config.disabled” under the “App_Config/Include/Feature” folder inside webroot
  2. Switch back to Form Authentication
    • Open the web.config the modify the following configuration
      • Remove this linece-switch-back-formauthentication-1
      • Change the authentication mode from “None” to “Form”<+++> Mode = “None”

        ce-authentication-none<+++> Mode = “Form”

        ce-authentication-form.png

Solution No.2

Implement the custom processor and also a service to retrieve an HTML content. Then replace the original in¬†ceExport.pageProcessing pipeline. My implementation can be found from my repo which was forked from original Sitecore’s repo and plus my module – Foundation.CreativeExchange

  1. Implement PageRequestServiceOverride  for our own
    • Override the GetCookieContainer methodPageRequestServiceOverride.cs
  2. Implement PageRequestOverride processor for our own
    • Override the¬†InitPageRequestService methodPageRequestOverride.cs
  3. Replace the original –Sitecore.XA.Feature.CreativeExchange.Pipelines.Export.PageProcessing.PageRequestOverride via patch file
    ce-patch-replace-pagerequest-processor

Done, you can export the HTML as normal via Creative Exchange feature. 

Resources

  1. Install Sitecore.HabitatHome.Platform
  2. Using Federated Authentication with Sitecore

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s