Embedding with Seamless JsConnect
Our technical overview explains how to set up JsConnect SSO for site-wide SSO. However, if you have Vanilla embedded in a page you’ll notice that the SSO doesn’t automatically sign you in even if users are signed in to the containing page. In order to make the sign in seamless you need to add some SSO information to your embed code.
Important Note: Attempting embedded SSO across two domains will not work in the Mobile Safari browser (and therefore, on all Apple devices).
To solve this, your forum must be hosted on a subdomain of your main site. For example, if your site is url.com, you could put your forum on forum.url.com, and then embed it from there. This sidesteps Mobile Safari’s issue, and potentially increases your search engine value as well. Our clients can change their forum to a subdomain of their site by going to “Customize Domain” in their Dashboard and following the instructions there.
Now, on to revising your embed code with some additional SSO information.
Vanilla Embed Code
Consider the embed code for Vanilla comments:
/*** Required Settings: Edit BEFORE pasting into your web page ***/
var vanilla_forum_url = 'http://forum.example.com/'; // The full http url & path to your vanilla forum
var vanilla_identifier = 'your-content-identifier'; // Your unique identifier for the content being commented on
**var vanilla_sso = 'SSO STRING'; // Your SSO string.**
/*** DON'T EDIT BELOW THIS LINE ***/
var vanilla = document.createElement('script');
var timestamp = new Date().getTime();
vanilla.src = vanilla_forum_url + '/js/embed.js';
(document.getElementsByTagName('head') || document.getElementsByTagName('body')).appendChild(vanilla);
If you declare
vanilla_sso and give it the proper value, then Vanilla will be able to sign in your user. To generate your SSO string:
- Start with the signed in user. This has the same fields as the user from the seamless setup.
- Add your client_id to the user so Vanilla will know how to identify you.
- JSON encode the user.
- Base64 encode the user in UTF-8. This is your signature string.
- Sign the signature string with your signature and the current timestamp using HMAC SHA1. Confirm the signature string is hex encoded.
signature = hmacsha1(signature_string + " " + timestamp, secret);
- Build your final sso string:
vanilla_sso = signature_string + " " + signature + " " + timestamp + " hmacsha1"
That’s it! The value of
vanilla_sso from above is what you put in your embed code. Since this needs to be dynamically generated by your site you cannot use SSO on a static page.
- The above example is for blog comments. For a full forum embed, use the code provided under “Forum Embed” in the Dashboard.
- Even though your signature string is base64 encoded, make sure the actual signature is hex encoded. The correct string will be 40 characters consisting of the numbers 0-9 and a-f.
- The timestamp is a unix timestamp. That means it will be an integer representing the number of seconds since 1 January 1970. Most languages have a way of getting this timestamp.