This script will add a global Lumi object to the window object, which can be called via window.Lumi
2. Identify users via SSO-Token
These are instructions on how to generate Single Sign-On tokens on your server. These tokens can be used to authenticate your users in our SDK. You can find the required private API key at https://app.Lumi.education/dashboard/user/api
Store your private key on your server and don't share it.
When a user wants to use the widget, request your server to generate an SSO token.
On your server, generate a token using the snippet below.
Pass the token back to your app and into our widget.
We will use that token to authenticate your user.
2.1. Install a JWT library
We use JSON Web Tokens to securely authenticate your users. First, install the appropriate JWT library for your server.
npm install --save jsonwebtoken
# See instructions here:https://www.nuget.org/packages/System.IdentityModel.Tokens.Jwt/
go get github.com/golang-jwt/jwt
# See instructions here:https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt/0.7.0
composer require firebase/php-jwt
pip install PyJWT
sudo gem install jwt
2.2. Generate tokens on your server
var jwt =require('jsonwebtoken');var PrivateAPIKey = <privateAPIKey>; // private API key is found on https://app.Lumi.education/dashboard/user/apifunction createLumiToken(user) { var userData = { id:user.id,// These are optional username:user.username, email:user.email, imageUrl:user.imageUrl }; return jwt.sign(userData, PrivateAPIKey, {algorithm:'HS256'});}
publicclassLumiTokenCreator{privatestaticstring PrivateKey =<PrivateAPIKey>; // private API key is found on https://app.LupublicstaticstringCreateToken(User user) {byte[] keyBytes =Encoding.UTF8.GetBytes(PrivateKey);var securityKey =newSymmetricSecurityKey(keyBytes);var credentials =newSigningCredentials(securityKey,"HS256");var header =newJwtHeader(credentials);var payload =newJwtPayload { { "id":user.id }, // these are optional { "imageUrl":user.imageUrl }, { "email":user.email }, { "username":user.username } };var securityToken =newJwtSecurityToken(header, payload);var handler =newJwtSecurityTokenHandler();returnhandler.WriteToken(securityToken); }}
import ("github.com/golang-jwt/jwt")const PrivateKey ="<PrivateAPIKey>"// private API key is found on https://app.Lumi.education/dashboard/user/apifunccreateLumiToken(user map[string]interface{}) (string, error) { token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{"id": user["id"],// optional"imageUrl": user["imageUrl"], "email": user["email"],"username": user["username"], })return token.SignedString([]byte(PrivateKey));}
importjava.util.HashMap;importio.jsonwebtoken.Jwts;importio.jsonwebtoken.SignatureAlgorithm;publicclassLumiTokenCreator { private static final String PrivateKey = "<PrivateAPIKey"; // private API key is found on https://app.Lumi.education/dashboard/user/api
publicstaticStringcreateToken(User user) throwsException {HashMap<String,Object> userData =newHashMap<String,Object>();userData.put("id",user.id);// optional, but preferreduserData.put("imageUrl",user.imageUrl); userData.put("email",user.email);userData.put("username",user.username);returnJwts.builder().setClaims(userData).signWith(SignatureAlgorithm.HS256,PrivateKey.getBytes("UTF-8")).compact(); }}
use\Firebase\JWT\JWT;const PrivateKey ='<PrivateAPIKey>'; // private API key is found on https://app.Lumi.education/dashboard/user/apifunctioncreateLumiToken($user) { $userData = ['id'=> $user['id'],// optional, but preferred'imageUrl'=> $user['imageUrl'],'email'=> $user['email'],'username'=> $user['username'], ];returnJWT::encode($userData, PrivateKey,'HS256');}
import jwtprivate_key ='<PrivateAPIKey'# private API key is found on https://app.Lumi.education/dashboard/user/apidefcreate_lumi_token(user): user_data ={'id': user.id,'imageUrl': user.image_url,# optional, but preferred'email': user.email,'username': user.username,}return jwt.encode(user_data, private_key, algorithm='HS256')
require'jwt'PrivateKey='<PrivateAPIKey'# private API key is found on https://app.Lumi.education/dashboard/user/apidefcreateLumiToken(user) userData = { id: user.id,# optional, but preferred imageUrl: user.image_url, email: user.email, username: user.username }JWT.encode(userData,PrivateKey,'HS256')end