Today we will walk through steps about extending your Sitecore Identity Server 9.3 to work with Facebook sub-provider. We will be creating a Sitecore Host plugin, which you should be familiar if your have read my previous blog on Sitecore Host Plugins.
Why Facebook Logins?
The scenario is that you would like your front door visitor to your Sitecore based website to be able to authenticate using their Facebook logins.
The good news is that Sitecore Identity Server can be configured as a federation gateway which means we can leverage Facebook as external provider with little effort.
What steps are needed?
- Register your Sitecore Application on the Facebook For Developers Portal. This process is to get an Application Identifier and Application Secret, that are needed in your Sitecore Instance. I will walk with you on how to do this process.
- Create and deploy a Sitecore Host Plugin that extends Sitecore Identity Server to support Facebook Logins. I will walk with you on how to create this plugin, with full access to the source code in my GitHub Repository
Register your Sitecore Application
Head to Facebook for Developers portal. On the portal, follow the link to create a new application. This will require you to specify the application display name after which, you will get a dashboard similar to this below.
Ensure you configure a redirect URL for your Sitecore Identity Server instance and save your changes. This will be of the format below:
For example, my SI redirect URL is https://sc93identityserver.dev.local/signin-facebook
Creating Sitecore Host Plugin for Facebook Login
I have previously blogged on how to create a Visual Studio project for your Sitecore Host plugin. I will recommend you have a read before proceeding further.
We need to reference the Microsoft.AspNetCore.Authentication.Facebook package needed for Facebook login functionality for ASP.NET core applications. This is it.
Facebook AppId and AppSecret configuration
Within our Sitecore Host Plugin configuration file, we will define two properties as follows:
AppId – This will be mapped to the Application Identifier available from Facebook for Developers portal
AppSecret – This will be mapped to the Application secret availabe form Facebook for Developer portal
Provide definition of ConfigureServices for the Plugin
As per Sitecore Host Plugin requirements, we need to configure services for the subprovider according to the instructions for this provider, and specify the
SignInScheme setting as
To use authentication middleware, we must have an object of the type
To initialise this object, we must use
Notice how we use
AuthenticationBuilder(services).AddFacebook() pipeline below, which is available to us via the Microsoft.AspNetCore.Authentication.Facebook package we referenced earlier.
Facebook Plugin in Action
After successful deployment of this plugin to your instance of Sitecore Identity server, you should see the Sitecore Identity login screen below.
Please note you will need to re-start your IIS to pick the plugin changes.
This is it. You now have a working Facebook Plugin that you can deploy to your Sitecore Identity Server 9.3 instance. The full source code for this plugin is available on my public GitHub Repository.