Node生成access token - GoEasy客户端安全

安装jsonwebtoken

    npm install jsonwebtoken

PubSub


    let jwt = require('jsonwebtoken');

    let id = 'user-001'; 
    let protectedChannel = 'protected-payment'; 

    let payload = {
        id: id,  //发送方,必须与connect GoEasy时传入的id一致
        channel: protectedChannel, //接收方,授权的channel
        w: true, //写权限,是否允许发送(publish)
        r: true //读全新,是否允许接收(subscriber)
    };

    let options = {
        expiresIn: "3h"  //token的有效时间,最长不能超过3小时,为了安全,GoEasy不接受有效时间大于3小时的access token
    };

    let secretKey = 'f7e4cf0f5c6db52d';  //应用的秘钥Secret key,登陆GoEasy->应用详情->Professional keys->Secret key


    //签名,生成access token
    let accessToken = jwt.sign(payload, secretKey, options);

IM

私聊


    let jwt = require('jsonwebtoken');

    let id = 'user-001'; //发送方,必须与connect GoEasy时传入的id一致
    let toId = 'user-002'; //接收方,私聊对象的id

    let payload = {
        id: id,
        to:toId,
        w: true, //写权限,是否允许发送
    };

    let options = {
        expiresIn: "3h"  //token的有效时间,最长不能超过3小时,为了安全,GoEasy不接受有效时间大于3小时的accessToken
    };

    let secretKey = 'f7e4cf0f5c6db52d';  //应用的秘钥Secret key,登陆GoEasy->应用详情->Professional keys->Secret key

    //签名,生成access token
    let accessToken = jwt.sign(payload, secretKey, options);

群聊


    let jwt = require('jsonwebtoken');

    let id = 'user-001'; //发送方,必须与connect GoEasy时传入的id一致
    let groupIds = ['group001']; //接收方,需要授权的groupId列表, 支持一次为多个群授权

    let payload = {
        id: id,
        to: groupIds,
        w: true, //写权限,是否允许发送
        r: true, //写权限,是否允许订阅群消息
    };

    let options = {
        expiresIn: "3h"  //token的有效时间,最长不能超过3小时,为了安全,GoEasy不接受有效时间大于3小时的accessToken
    };

    let secretKey = 'f7e4cf0f5c6db52d';  //应用的秘钥Secret key,登陆GoEasy->应用详情->Professional keys->Secret key

    //签名,生成access token
    let accessToken = jwt.sign(payload, secretKey, options);

results matching ""

    No results matching ""