Quick Start

Frontend SDKs

Web SDK

Step 1. Include the SDK and dependencies in your html file

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

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

Step 2. Create an instance of the SDK in your script

<script type="text/javascript">
    // You can find all necessary info for your integration in Control panel
    var kwsSdk = new KwsSdk({
        clientId: 'your_client_id',
        clubUrl: 'https://examplekwsclub.com',
        kwsApiHost: 'https://examplekwsapihost.com',
        language: 'en', // The language of your frontend here
        implicit: false, // Set to true if using OAuth implicit flow
        crossDomain: false,
        callbackHost: 'https://myappdomain.com', // The OAuth callback URL
    });
</script>

Learn more

Step 3. Add login button pointing KWS in your app

<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>

Step 4. Add a call to get the user data when logged

<script type="text/javascript">
    // Now you can use the SDK to make API calls. See reference section
    kwsSdk.app.user.get()
        .then(function (userData) {
            console.log('Got user data', userData);
        })
        .catch(function () {
            console.log('Call failed. User is not authenticated');
        })
        .finally(function () {
            console.log('This is always called at the end when the response is received');
        });
</script>

In the example we are just printing the data in the console, but you can display the user data you want wherever you need to. For example, names and address in a profile page or points in a fancy score box.

When you log in through the single sign on and you are redirected to your app site, you should see user data printed in the console. If you get errors, make sure you added the OAuth redirect URL, also known as callback host, and you are using the implicit flow or you already implemented the backend SDK in your app backend code. More about the last here

More about Frontend SDK

The Web SDK helps you interact with KWS from your frontend and is used to enable the following experiences:

Backend SDKs

Nodejs SDK

The Node.js SDK integrates very easily with apps based on express.js

Step 1. Install the latest version of the KWS Node.js SDK in your project

npm install --save sa-kws-node-sdk

Step 2. Create an instance of the SDK in your code

var KwsSdk = require('sa-kws-node-sdk');

// KWS will provide all the necessary info for your account
var kwsSdk = new KwsSdk({
    clientId: 'your_client_id',
    apiKey: 'your_api_key',
    kwsApiHost: 'https://examplekwsapihost.com'
});

Learn more

Step 3. Include the callback handlers for user authentication

// assuming that app is your express.js instance object
app.use(kwsSdk.router);

More about Backend SDK

The Nodejs SDK helps you easily integrate your Node.js application with KWS and is used to enable the following experiences: