https://github.com/kanocomputing/kano-world-js-sdk
🚨Unmaintained 🚨Kano World JS SDK
https://github.com/kanocomputing/kano-world-js-sdk
Last synced: 8 months ago
JSON representation
🚨Unmaintained 🚨Kano World JS SDK
- Host: GitHub
- URL: https://github.com/kanocomputing/kano-world-js-sdk
- Owner: KanoComputing
- Created: 2014-12-01T18:27:51.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-01-18T15:00:01.000Z (over 7 years ago)
- Last Synced: 2024-04-11T15:53:39.062Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 215 KB
- Stars: 2
- Watchers: 24
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🚨Kano World JS SDK — Unmaintained 🚨
Lightweight JavaScript SDK with basic tools to integrate Kano World login and basic features.
**January 2019**: This project isn't being actively developed or maintained.
### Setup
You can import the sdk as a JS build:
```html
```
or with npm:
```
npm install --save kano-world-sdk
```
```javascript
var config = {
API_URL : 'https://api.kano.me',
WORLD_URL : 'http://world.kano.me'
};
var KW_SDK = require('kano-world-sdk')(config);
```
### Usage
To initialise the SDK, run:
```javascript
KW_SDK.init();
```
### Kano World login
There are a few ways to enable login with Kano World - the first one with the use of a button, or any element with the attribute `data-kano-world-login` set:
```html
Login with Kano World
```
Once logged in, you can display a button or HTML element to logout with the attribute `data-kano-world-logout` set.
```html
Logout
```
The `init` method on the SDK takes a callback that will be triggered once the user completed authentication. The callback will be fired in case of success or failure, in which case it will contain an error.
Otherwise, you can now used logged in features and methods, and the API calls made throught `KW_SDK.api.*` will use the user's credentials.
```javascript
KW_SDK.init(function (err, user) {
// This callback will be triggered once the user logs in successfully.
if (err) {
alert('Login failed: ' + err.toString());
return;
}
alert('User logged in as: ' + user.username);
});
```
If you need to access the user object in any other moment, you can use the `auth` module:
```javascript
console.log(KW_SDK.auth.getUser());
```
If you want to trigger the login on Kano World via code instead of using the button attribute, you can call:
```javascript
KW_SDK.auth.login();
// This method will redirect to Kano World and come back after authentication complete.
```
Also, you can logout by calling:
```javascript
KW_SDK.auth.logout();
// This method will forget your token and refresh.
```
App storage
Once logged in, the app storage module allows you to access and change profile stats into a specific app namespace of your profile, without seeing any of the rest.
Use it like this:
```javascript
KW_SDK.init(function (err) {
if (err) { throw err; }
// User logged in
KW_SDK.appStorage.set('my-app-name', { level: 1 }, function (err) {
if (err) { throw err; }
// Data stored on your profile stats
KW_SDK.appStorage.get('my-app-name', function (err, data) {
if (err) { throw err; }
console.log(data);
// { level: 1 }
});
});
});
```
### Custom Elements
You can register custom elements for login/register forms. These forms will take care of the field validation and authentication
and trigger events to notify when login/register/errors occurs.
You can register these elements like so:
```js
KW_SDK.registerForms();
```
You will then be able to use them in your HTML pages.
Available elements:
#### kano-login-form
Display a complete login form.
Usage:
```html
```
Events:
- success: The authentication process succeeded. (Will contain the session in the `details` attribute)
- error: The authentication process failed.
#### kano-register-form
Display a complete register form.
Usage:
```html
```
Events:
- success: The authentication process succeeded. (Will contain the session in the `details` attribute)
- error: The authentication process failed.