Web SDK

Info Contents
Version 2.0.0
Support kws-support@superawesome.tv
License GNU Lesser General Public License Version 3

Note

  • In order to avoid backward compatibility issues some functions are prefix with a version number like this v1.user.get.
  • It is because a new version of this function is (or will be) available.
  • The current version of the function is never prefixed.
  • So in order for you to not have to change your entire source code later you can use the function with the version prefixed with a 100% backward compatibility guaranteed

Including the sources in your html

<head>
    <!-- (...) -->

    <!-- KWS SDK -->
    <script type="text/javascript" src="https://kws-sdk.superawesome.tv?v=2"></script>
</head>

Instantiating the SDK

// KWS will provide all the necessary info for your account
var kwsSdk = new KwsSdk({
    clientId: 'your_client_id',
    kwsApiHost: 'https://examplekwsapihost.com',
    clubUrl: 'https://examplekwsclub.com',
    language: 'en',  // The language of your frontend here

    /*(optional) if set must contain the token of the user. (useful when working with iframe) */
    token: 'BEARER TOKEN HERE',
    /*(optional) if set to true won't init the notification */
    withoutNotifications: false,
    /*(optional) if set to true will use the implicit flow */
    implicit: false,
    /*(optional) if set to true will will consider the backend as a different domain */
    crossDomain: true,
    /*(optional) must contain the backend url if `crossDomain` is set to true */
    callbackHost: 'https://yourbackendurl.com'
});

Login or logout

If the user is not logged in you want to display a login button, if the user is currently logged in you want to display a logout button instead. When you click on the button you call the action from the SDK to log in or log out.

<body>
    <button id="login" class="sa_sign_in" onclick="kwsSdk.signIn()"></button>
    <br/>
    <a href="#" id="logout" onclick="kwsSdk.signOut()">Logout (<span id="displayName"></span>)</a>
</body>
var kwsSdk = new KwsSdk({
    clientId: 'your_client_id',
    kwsApiHost: 'https://examplekwsapihost.com',
    clubUrl: 'https://examplekwsclub.com',
    language: 'en'  // The language of your frontend here
});

kwsSdk.app.user.get()
    .then(function(user){
        console.log('Got user data', user);
        document.getElementById('logout').style.display = 'block';
        document.getElementById('login').style.display = 'none';
        document.getElementById('displayName').innerHTML = user.username;
    })
    .catch(function(){
        console.log('Call failed. User is not authenticated');
        document.getElementById('logout').style.display = 'none';
        document.getElementById('login').style.display = 'block';
    })
    .finally(function(){
        console.log('This is always called at the end when the response is received');
    });

{{AUTOMATIC_DOCUMENTATION}}