Integrating the Vanilla Forum

One of the more commonly requested applications for MODx is a forum package. While Revolution will soon have a native forum add-on, Discuss, there are some advantages to using a full-blown forum application. The trick is for your visitors to not have to log on in different places, once in MODx and again in the forum. This means some kind of single sign-on user integration between MODx and the forum software. The latest major release of the Vanilla forum software, Vanilla 2, offers just this. I recently had the opportunity to make use of this Vanilla plugin, and after an initial period of confusion, found it to be shockingly simple to use with MODx.

The Vanilla Side

As of this writing, the latest version of Vanilla is 2.0.3, and you can get it here. Installing and setting up your Vanilla forum, and customizing its theme to match your MODx site (which is nearly as easy as working with MODx templates) is not within the scope of this article. The Vanilla documentation will do a much better job of explaining basic Vanilla functions.

Once you have your Vanilla forum configured, themed, and working the way you want, it's time to set up the ProxyConnect SSO plugin. Get the plugin here. Simply upload the ProxyConnect folder to the forum's plugins folder along with the other plugins.

Login to your forum and go to the Dashboard, and go to Plugins. Enable the Proxy Connect SSO plugin.

ProxyConnect Plugin Settings

Now go to its Settings. Choose the ProxyConnect authenticator from the drop-down and activate it.

Choose Authenticator

Fill in the fields for your main site URL and for the URLs to the MODx pages you'll be using for registration, login and logout pages. If you're using the standard WebLogin snippet for MODx logins, add the ?webloginmode=lo to the logout URL.

And that's it for the Vanilla side. Log out of Vanilla.

The MODx side

You'll need to create a snippet and a plugin, and at least two resources to enable the MODx side of ProxyConnect SSO.

The snippet, to generate the list of user data Vanilla needs to integrate the users.

if(isset($_SESSION['webInternalKey'])) {
$output = "UniqueID=" . $_SESSION['webInternalKey'] . "\n\n";
$output .= "Name=" . $_SESSION['webShortname'] . "\n\n";
$output .= "Email=" . $_SESSION['webEmail'] . "\n\n";
return $output;
}
return;

The plugin, to integrate the logout from MODx to Vanilla. All this needs to do is to remove the Vanilla cookie. The plugin uses the OnWebLogout system event, so check that one in the plugin's System Events tab. Make sure to edit the .mydomain.com part to fit your domain!

$e = &$modx->Event;

switch($e->name) {
    case 'OnWebLogout': // integrated logout
            setcookie('Vanilla', ' ', time() - 3600, '/', '.mydomain.com');
            unset($_COOKIE['Vanilla']);
    break;
}

Create a resource with a blank template, and just put the tags for the snippet you created as its content. The alias of the page must match the URL you provided in the ProxyConnect setting for it.

Create the resource or resources you'll be using for login/logout and registration. It can all be on one page; again make sure the alias is the same as the URL you gave the relevant ProxyConnect settings.

And finally, create a new webuser with the same login name, password, and email as your Vanilla admin user. Log in to MODx with that user, then go to your forum. You'll get a popup asking if you want to create a new Vanilla user, or link to an existing account. Choose to link to the existing account. If all goes as expected, you should find yourself logged in to Vanilla as the admin user.

You probably won't want all of your web users to be presented with that popup dialog when they first go to the forums, so add this line to your Vanilla config.php file.

$Configuration['Garden']['Authenticator']['SyncScreen'] = FALSE;

When a visitor goes to the Forum, it will open a socket to the URL you specified in the ProxyConnect Authenticate URL setting field, passing the MODx cookie as if it were a regular visitor requesting the page. This will load up the MODx SESSION for the user using the session ID set in the cookie, and the snippet in that resource will output the necessary user data. Vanilla will scrape the data from the page, and check this data against its user database. If the user does not exist, Vanilla will create it automatically, and in any case (short of an actual mismatch in the user data) the user will now be logged in to Vanilla. The Vanilla links for login, logout and registration will be redirected to the MODx pages specified in the respective ProxyConnect setting fields.