Enable Sitecore-integrated federated authentication
When running a JSS application in integrated mode, you can use the Sitecore built-in Owin support to delegate authentication and map users into the Sitecore security model.
This approach does not work in headless or connected modes, because it depends on browser requests directly to Sitecore.
To enable federated authentication:
-
Refer to the documentation on Using federated authentication with Sitecore for some configuration steps.
-
Configure federated authentication with a provider of your choice.
-
Extend the Layout Service context to add Sitecore-generated login URLs to the Layout Service output.
TipRefer to the documentation for Extending context data returned by the Layout Service.
For example:
RequestResponseusing System.Linq; using Sitecore.Abstractions; using Sitecore.LayoutService.ItemRendering.Pipelines.GetLayoutServiceContext; using Sitecore.Pipelines.GetSignInUrlInfo; public class AddLoginLinks : Sitecore.JavaScriptServices.ViewEngine.LayoutService.Pipelines.GetLayoutServiceContext.JssGetLayoutServiceContextProcessor { protected readonly BaseCorePipelineManager CorePipelineManager; protected readonly BaseLinkManager LinkManager; public AddLoginLinks(Sitecore.JavaScriptServices.Configuration.IConfigurationResolver configurationResolver, BaseCorePipelineManager corePipelineManager, BaseLinkManager linkManager) : base(configurationResolver) { CorePipelineManager = corePipelineManager; LinkManager = linkManager; } protected override void DoProcess(GetLayoutServiceContextArgs args, Sitecore.JavaScriptServices.Configuration.AppConfiguration application) { var returnUrl = LinkManager.GetItemUrl(args.RenderedItem); var loginUrlArgs = new GetSignInUrlInfoArgs(site: "JssReactWeb", returnUrl: returnUrl); GetSignInUrlInfoPipeline.Run(CorePipelineManager, loginUrlArgs); if (loginUrlArgs.Result.Any())extend the Layout Service context { args.ContextData.Add("loginUrls", loginUrlArgs.Result); } } }
-
Verify you have the desired output returned from the Layout Service. Based on the customization in the previous step, the JSON data returned from the Layout Service should contain:
RequestResponseloginUrls: [ { identityProvider: "Auth0", caption: "Log in with Auth0", icon: "/sitecore/shell/themes/standard/Images/24x24/helloworld", href: "/identity/externallogin?authenticationType=Auth0&ReturnUrl=%2fidentity%2fexternallogincallback%3fReturnUrl%3d%252fservices%26sc_site%3djssreactweb%26authenticationSource%3dDefault&sc_site=JssReactWeb" } ]