Using Facebook Login with Sitecore Identity 9.3

Facebook for developers

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?

  1. 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.
  2. 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.

Application Dashboard

Ensure you configure a redirect URL for your Sitecore Identity Server instance and save your changes. This will be of the format below:

https://Your_SI_Base_Url/signin-facebook

For example, my SI redirect URL is https://sc93identityserver.dev.local/signin-facebook

Creating Sitecore Host Plugin for Facebook Login

Sitecore Host Facebook Plugin

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 idsrv.external

To use authentication middleware, we must have an object of the type Microsoft.AspNetCore.Authentication.AuthenticationBuilder

To initialise this object, we must use 

new Microsoft.AspNetCore.Authentication.AuthenticationBuilder(services) 

instead of services.AddAuthentication()

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 – ConfigureServices code listing

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.

Source code

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.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.