Sitecore is a popular .NET based Enterprise Content Management system that when coupled with Telligent Community provides a powerful platform for customer engagement. Because they are built on the same underlying technology, the REST SDK makes integrating the 2 systems together easier.
Installation and Configuration
Since this is an SDK, there is an assumption that somewhere you have setup a Visual Studio solution that you are using to develop Sitecore components. The easiest way to start using the SDK is to install it into this solution using NuGet. For more detailed instructions on how to install, review the REST SDK article's ""How to Get It" topic. This process will install the supporting files and references needed to begin configuring the SDK for first use.
Once installed, you need to decide which Host you wish to use. You should take some time to review the Hosts topic to understand what they are and how they work. The configuration of the SDK depends on the choice you make. Here is a quick overview of the 2 available hosts that may help you choose the best path to continue reading about:
Default REST Host - This is by the far the most feature-rich of the 2 hosts. It also requires the most configuration, all of which is covered in more detail in the Default REST Host topic. This host is capable of:
- Performing all the Basic Requests of the SDK
- Optional Single Sign-On that automatically handles user creation and synchronization in the community
- Url proxying- You can create a special code handler the allows you to intercept community based urls and in turn provide and alternate url inside of Sitecore.
- Multiple Host support if for some reason you wanted to manage different hosts for different reasons, such as multi-tenancy.
Client Credentials REST Host - If you just want to surface some information your Sitecore site, like a list of blogs or forum threads and don't need all the additional functionality or you want more granular control over how everything works then this host may be appropriate. This host is the simplest of the hosts as it allows you to just make REST calls using Oauth and not have to worry about managing OAuth tokens. With this host you can:
- Perform all the Basic Requests of the SDK
- Act as a single user or impersonate other users in the community
Unlike the the Default REST Host you don't need to add any additional configuration in Sitecore aside from some optional web.config parameters. Most of the use of this host is code based.
Default REST Host and Sitecore
Unlike the Client Credentials REST Host, the Default REST Host needs to be initialized and configured in code depending on the features you use. It is recommended that this all be done in the application start or as close to it as possible. One proven way to do this in Sitecore is to use a pipeline. Here is an example of initializing the host in a pipeline:
using Sitecore; using Sitecore.Pipelines; using Telligent.Evolution.Extensibility.Rest.Version1; namespace Telligent.Rest.SDK.Sitecore.Pipelines { public class InitializeHost { public virtual void Process(PipelineArgs args) { Host.Get("default"); } } }
Then using the Sitecore configuration files you insert it into the <initialize /> pipeline:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <pipelines> <initialize> <processor type="Telligent.Rest.SDK.Sitecore.Pipelines.InitializeHost, Telligent.SitecoreSDK" /> </initialize> </pipelines> </sitecore> </configuration>
Now that you have this in place, you can use this host reference to set up additional features described in the Default REST Host topic.
If you choose to use Sitecore accounts as the basis for your community, you can use this pipeline to configure how the host gets your authenticated user:
using Sitecore; using Sitecore.Pipelines; using Telligent.Evolution.Extensibility.Rest.Version1; namespace Telligent.Rest.SDK.Sitecore.Pipelines { public class InitializeHost { public virtual void Process(PipelineArgs args) { Host.Get("default").ResolveLocalUser = (host, resolveArgs) => { if (Context.User == null || !Context.User.IsAuthenticated) { return null; } return new LocalUser(Context.User.Name, Context.User.Profile.Email); }; //If you do not wish to use domain accounts //Host.Get("default").ResolveLocalUser = (host, resolveArgs) => //{ // if (Context.User == null || !Context.User.IsAuthenticated) // return null; // return new LocalUser(Context.User.LocalName, Context.User.Profile.Email); //}; } } }
For more information in this topic see the "Use Your Existing Accounts" topic in the Default REST Host article. Additionally, you can also add your delegates for the Url Proxying topic of the same article if you so choose to take advantage of that feature:
using Sitecore; using Sitecore.Pipelines; using Telligent.Evolution.Extensibility.Rest.Version1; namespace Telligent.Rest.SDK.Sitecore.Pipelines { public class InitializeHost { public virtual void Process(PipelineArgs args) { var host = Host.Get("default"); host.ResolveLocalUser = (host, resolveArgs) => { if (Context.User == null || !Context.User.IsAuthenticated) { return null; } return new LocalUser(Context.User.Name, Context.User.Profile.Email); }; host..GetRedirectUrl = (host, url, urlArgs) => { //The url parameter is the you can use it to evaluate if you need to redirect it. //Return the Url you wish to redirect to return url; }; } } }