Widget Authentication with Oauth2

If your site is restricted behind reader logins or one of the other security options we offer, you can enable the "Secure widget access using Oauth2" option on the widget settings page to give your readers access to your content inside of the widget.

When this option is enabled, the widget will not work unless a valid Oauth2 token is passed through on initiation. To pass the Oauth token through, make sure your widget embed code includes the applicable line from below:

//Modern Slideout Widget
_ko16_p.push(['_setToken', 'OAUTH2 TOKEN']);

//Legacy Popover Widgets
_helpgizmo_p.push(['_setToken', 'OAUTH2 TOKEN']);

To retrieve an Oauth2 token, you will first need to generate the Client Secret for your knowledge base. On the widget settings page, click on the "Generate Client Secret" button.

Now that you have your client secret and client ID, you can use them to request an access token from the Oauth token endpoint.  See below for workflow examples.

Request Token

//Basic curl request for token without reader information
curl -u clientID:clientSecret https://app.knowledgeowl.com/oauth2/token -d "grant_type=client_credentials"

//curl request for token with reader information
curl -u clientID:clientSecret https://app.knowledgeowl.com/oauth2/token 
-d "grant_type=client_credentials&reader[ssoid]=UID&reader[username]=reader@mysite.com&reader[groups]=Group1,Group2"

Example Response


Widget Embed Code with Token

var _ko16_p = _ko16_p || [];
_ko16_p.push(['_setProject', '123abc1231231abc123-123abn1231123abnc']);
_ko16_p.push(['_setToken', 'Oauth Token']);
(function() {
		var ko = document.createElement('script');
		ko.type = 'text/javascript';
		ko.async = true;
		ko.src = "//yourkbURL/javascript/ko-index?__pc=123abc1231231abc123-123abn1231123abnc"; //kb -- with demo content