How to Single Sign On (SSO) from Thinkific to WordPress
In this example, we will demonstrate how to log a user into WordPress from Thinkific. In other words, a user can click a link in Thinkific and be seamlessly logged into WordPress.
If you wish to log a user into Thinkific from WordPress, please see the main SSO plugin page here.
Required Plugins
Important
This a developer-focused article and will require you to make edits to your Theme in Thinkific. If you require assistance with this, please contact your developer or WooNinja to arrange consulting support.
Step 1 – Thinkific Theme Edit
You will need to insert a link in Thinkific by editing your theme. For example, if you wished to place an ‘Open WordPress’ link your users navigation menu, you would insert the following code in your header_user_menu Snippet:
<!-- WP SSO --> <li class="dropdown__menu-item"> {% assign timeStamp = 'now' | date: "%s" %} {% assign wp_sso_string = site.current_user.email | append: timeStamp | hmac_sha256: "YOUR_CHOSEN_KEY" %} <a href="http://example.com/thinkific-wp-sso?hash={{ wp_sso_string }}&email={{site.current_user.email}}×tamp={{ timeStamp}}"> Open WordPress </a> </li>
YOUR_CHOSEN_KEY – This is your secret string and it must not be shared or appear in your HTML mark up. By default, the plugin expects this to be your Thinkific API key. If you use a different secret, you will need to add a WordPress filter in your functions.php. We recommend using a lengthy, unique and non-dictionary based secret.
example.com – This should be your WordPress URL
/thinkific-wp-sso – This is the default end point that the SSO plugin will monitor in WordPress. If you wish to use a custom endpoint, you will need to add a WordPress filter in functions.php
timestamp – This is required. An SSO link is valid for a maximum of 5 minutes.
email – The user’s email, by default the currently logged in user in Thinkific. This email must match the email in WordPress.
By default, a user is not created if they do not exist in WordPress. If you wish to create a user in WordPress during the SSO flow, you should use the following action to create and log them in:
do_action('thinkific/sso/wp/user/create', $sentEmail, $sentHash);