100ms-management-token-generation-service

node v10.23.0
version: 1.0.0
endpointsharetweet
const { json, send } = require('micro'); const jwt = require('jsonwebtoken'); const uuid4 = require('uuid4'); const sendToken = ({token,res}) => { console.log(token); send(res, 200, { token:token }); } const generateToken = ({token_variables, secret, customer_id, res}) => { console.log(token_variables); console.log(secret); console.log(customer_id); jwt.sign(token_variables, secret, { algorithm: 'HS256', expiresIn: '24h', issuer: customer_id, jwtid: uuid4()},function(err, token) { // console.log("Error is "+ err); // console.log("Token is "+ token); if(err){ send(res, 400, {error:err}); } else{ sendToken({token, res}); } }); } exports.endpoint = async (req, res) => { console.log("Hello"); res.setHeader('Access-Control-Allow-Origin', '*') res.setHeader("Access-Control-Allow-Methods",'*') let payload; try { payload = await json(req); console.log(payload); } catch (error) { send(res, 400, { error }); return; } if (supportedEnvs.includes(env)) { const customer_id = process.env.hmsCustomerId; const secret = process.env.hmsManagementSecret; const management_key = process.env.hmsManagementKey; const token_variables = { access_key: management_key, }; // console.log("Room id is "+room_id); // console.log("Peer id is "+peer_id); // console.log("App id is "+app_id); // console.log("Customer id (env) is "+process.env.customerId); // console.log("Customer id is "+customer_id); // console.log("Access key is "+access_key); generateToken({token_variables, secret, customer_id, res}) } else{ const token = 'dummy'; console.log(token); sendToken({ token, res }) } }
Loading…

no comments

    sign in to comment