3 min to read
Sitecore JSS Adal Authentication
This post will focus on implementing Microsoft Azure’s ADAL. I also shared the JSS template which allows you to start with the ADAL connected JSS site immediately.
What is ADAL
The Windows Azure Authentication Library (ADAL) is a library meant to help developers to take advantage of Active Directory for enabling client apps to access protected resources.
Setting up your Azure configuration
- Set up an App Service for your website. Log in to https://portal.azure.com
- Click on
Azure Active Directory, click on
- in the top click on the button New Application Registration and then fill in the information you want. Note that the
Sign-on URLcorresponds to your local JSS site (dev URL).
- Hitting the create button we now get an overview of the created registration.
- When you click on settings you will be able to configure even more stuff. Dive into the Microsoft Azure docs for more info if you want to know more about that.
Retrieving the information
Now that you have registered your App you also need to have two keys. When you get more familiar with Azure you know that it’s full with ID’s and it can be a nightmare to get the right one:
- TENANT_ID - This is the ID of the Active Directory Service. You can find it under the properties of the Azure Active Directory tab.
- CLIENT_ID - This is the ID of your registered App, so go back to App registrations and it shows the ID on the right side.
Creating your JSS app
When you start a new project of course you want to use all kind of libraries you’re familiar with. For this reason I created a template for you which allows you to start right away with ADAL in your project. When you want to know more about Custom Templates take a look here.
Now let’s create a website with ADAL:
jss create ichabod react –repository garywenneker/jss-adal
Please note that ADAL has only been added to the React template (not for Angular and Vue).
Change to that directory and load up VSCode or whatever poison you’re using.
After filling in the right stuff and hitting off with
jss start we should see the actual AD login page:
Changes to make ADAL work
There are a few files which are different, compared to the original templates.
- package.json - added a reference to react-adal
- index.js - wrapping the app using ADAL
- **registerServiceWorker **- The service worker is a web API, that helps you cache your assets and other files, so that when the user is offline or on a slow network, he/she can still see results on the screen. As such, it helps you build a better user experience. That’s what you should know about service worker’s for now. It’s all about adding offline capabilities to your site.
- added AdalConfig.js - this is the place where you have to add your ID’s!!
An different way is to check the implementation. It’s a fork from the original templates: https://github.com/GaryWenneker/jss-adal