How To: Create your own external login source

How To: Create your own external login source

A while back we released a feature that allows certain ActiveCampaign products to authenticate users with an external login source. This feature is currently supported in KnowledgeBuilder 3.x and SupportTrio 2.x, and will soon be included in every ActiveCampaign product.
I wanted to share how dead simple it is to get started creating a new login source using your own authentication system. We’ve included some of the more popular applications like Joomla, PHPBB3, and vBulletin, as default external login sources, which can be enabled at any time.
But you may have your own custom authentication system that you’d like to use. In order to do this, you’ll need familiarity with editing PHP files, as well as a programmatic understanding of how to use PHP to speak to your authentication system.
To get started, open up the ac_global/loginsource/ directory contained within your KnowledgeBuilder 3.x or SupportTrio 2.x installation:
image 3783608
You’ll see a number of individual .php files, each corresponding to a separate login source configuration. For this example, I’ve added the last file, zencart.php, as we will be creating an external login source for Zen Cart.

Set up .php file

Once you create the new .php file in this directory, edit the contents of the file with this:

$loginident = "zencart";
$loginvars = "host,dbname,user,pass";

Here we specify the name of our new external login source (the $loginident variable), as well as the settings you’d like to specify when setting up this login source (the $loginvars variable).
The $loginident variable will correspond with the name you see listed under the available login sources within the application:
image 6893453
The $loginvars variable will correspond with the available fields that allow you to input specific information pertaining to this login source:
image 3117855
Once you have included those two variables in the new .php file, you should be able to access the login source directly within the application:
image 8490429

Enable and further configure .php file

Once you’ve saved your new login source settings, using the above application pages, you are ready to configure the .php file to speak to your authentication system.
The easiest way to set up the rest of the .php file is to copy an existing source. For example, if you open vbulletin.php, you’ll see the necessary functions that need to reside within the class:

class vBulletinLoginSource extends AC_LoginSource {

Modify names to match your new login source. For example, vBulletinLoginSource would become zencartLoginSource.
Keep the five core functions in place:
image 7259881
Modify these functions to extract and authenticate a given username/password combination. For more information on what each of these functions should return, please view our detailed help documentation article.
We can also set this up for you, if you provide us the database structure that houses your external user credentials, as well as any specific PHP authentication/validation functions.

Testing out your new login source

If you feel confident that you’ve modified the .php file correctly, the only thing left is to test it out!
Make sure you’ve enabled your new login source, set User Type to Public or Admin, and promote it to be the first login source the system tries to use for authentication:
image 6196894
Then, log out of the application, and try logging in as a user from your external system. If everything is working, you should be able to log straight in to the application as normal!

Never miss an update