WHMCS Based Login for WordPress

 This is to share the experience of a cool project I completed recently.

It is perfect integration to have users login to WordPress site, a web hosting solution, using WHMCS being a Web Hosting Billing & Automation Platform. We have a plan to extend this further to other web hosting solutions in use. For this particular integration we have two requirements.

  • Users in WHMCS should be able to seamlessly login to Wordpress to manage it.
  • If the user authenticated at WHMCS is already present in WordPress link them, else create a new user with the details received from WHMCS.

We have the well known standard protocols used for similar scenarios based on SAML 2.0 (http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0.html) and OpenIDConnect 1.0 (https://openid.net/connect/). Based on the future direction, wide usage and availability of plugins we selected OIDC(OpenID Connect) to go forward. There were whole lot of plugins available for us in this journey to select on.

Below is the flow in brief.

  • User clicks on ‘Login with WHMCS’ option we configured in the WordPress login as below.
Login Options
  • User is redirected to WHMCS. Technically an authorization code based OIDC flow is initiated, requesting the scopes of openid, profile and email.
  • User enter credentials at WHMCS site, provide any required consents. Upon successful authentication user is redirected back to a “callback_url” we have in WordPress site along with an authorization code.
  • Underneath we exchange this is an access token, which provides us with an IDToken as well, will user details. In the WHCMS case, they only gave ‘sub’ claim specific to user within this IDtoken.
  • Just IDtoken is not giving us enough information. So to retrieve more information we make another /userinfo call as per the OpenIDConnect specification, which gives us more information from WHMCS given an authorized token as below.
{
“email”: “
kladrock@kladrock.com”,
“email_verified”: false,
“name”: "
KladRock",
“family_name”: “Rock”,
“given_name”: “KladRock”,
“preferred_username”: “kladrock”,
“locale”: “en-GB”,
“update_at”: “2020–07–18 17:14:33”,
“sub”: “xxxx-xxx-x-xxxx-xxxx”
}

Yeah! Now we have enough information populate this user at WordPress side if needed or link to an existing user. Expect more as we expand this solution.

Below are some memos from the journey. :)

Configuring WHMCS with Wordpress as an OIDC client(service provider)
Whole lot of plugins we have for SSO

Hint for my friends: You will see a lot of Miniorange plugins there. It’s good to start with, but moving forward they limit the functionality to upgrade to premium such as role-mapping is not available in free version, only 10 users will be provisioned etc. Unless you are ready to spend that, there are fully open source solutions. Read their limitations if possible and see if it fits you beforehand.

Reach out me at https://www.fiverr.com/kladrock for any projects/consultancy.

Comments

Popular posts from this blog

Sign into Dokuwiki with Google

Single Sign On Integrations - Intro

Shibboleth based SSO for SAP