[mirotalksfu] - add token endpoint
هذا الالتزام موجود في:
@@ -41,7 +41,7 @@ dependencies: {
|
||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||
* @version 1.3.75
|
||||
* @version 1.3.76
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -579,7 +579,7 @@ function startServer() {
|
||||
return res.status(403).json({ error: 'Unauthorized!' });
|
||||
}
|
||||
// setup meeting URL
|
||||
let meetingURL = api.getMeetingURL();
|
||||
const meetingURL = api.getMeetingURL();
|
||||
res.json({ meeting: meetingURL });
|
||||
// log.debug the output if all done
|
||||
log.debug('MiroTalk get meeting - Authorized', {
|
||||
@@ -608,7 +608,7 @@ function startServer() {
|
||||
return res.status(403).json({ error: 'Unauthorized!' });
|
||||
}
|
||||
// setup Join URL
|
||||
let joinURL = api.getJoinURL(req.body);
|
||||
const joinURL = api.getJoinURL(req.body);
|
||||
res.json({ join: joinURL });
|
||||
// log.debug the output if all done
|
||||
log.debug('MiroTalk get join - Authorized', {
|
||||
@@ -618,6 +618,35 @@ function startServer() {
|
||||
});
|
||||
});
|
||||
|
||||
// request token endpoint
|
||||
app.post([restApi.basePath + '/token'], (req, res) => {
|
||||
// Check if endpoint allowed
|
||||
if (restApi.allowed && !restApi.allowed.token) {
|
||||
return res.status(403).json({
|
||||
error: 'This endpoint has been disabled. Please contact the administrator for further information.',
|
||||
});
|
||||
}
|
||||
// check if user was authorized for the api call
|
||||
const { host, authorization } = req.headers;
|
||||
const api = new ServerApi(host, authorization);
|
||||
if (!api.isAuthorized()) {
|
||||
log.debug('MiroTalk get token - Unauthorized', {
|
||||
header: req.headers,
|
||||
body: req.body,
|
||||
});
|
||||
return res.status(403).json({ error: 'Unauthorized!' });
|
||||
}
|
||||
// Get Token
|
||||
const token = api.getToken(req.body);
|
||||
res.json({ token: token });
|
||||
// log.debug the output if all done
|
||||
log.debug('MiroTalk get token - Authorized', {
|
||||
header: req.headers,
|
||||
body: req.body,
|
||||
token: token,
|
||||
});
|
||||
});
|
||||
|
||||
// ####################################################
|
||||
// SLACK API
|
||||
// ####################################################
|
||||
|
||||
@@ -28,49 +28,46 @@ module.exports = class ServerApi {
|
||||
const { room, roomPassword, name, audio, video, screen, notify, token } = data;
|
||||
|
||||
const roomValue = room || uuidV4();
|
||||
const roomPasswordValue = roomPassword || false;
|
||||
const nameValue = name || 'User-' + this.getRandomNumber();
|
||||
const roomPasswordValue = roomPassword || false;
|
||||
const audioValue = audio || false;
|
||||
const videoValue = video || false;
|
||||
const screenValue = screen || false;
|
||||
const notifyValue = notify || false;
|
||||
const jwtToken = token ? '&token=' + this.getToken(token) : '';
|
||||
|
||||
let jwtToken = '';
|
||||
|
||||
if (token) {
|
||||
// JWT.io
|
||||
const { username, password, presenter, expire } = token;
|
||||
|
||||
const usernameValue = username || 'username';
|
||||
const passwordValue = password || 'password';
|
||||
const presenterValue = String(presenter);
|
||||
const expireValue = expire || JWT_EXP;
|
||||
|
||||
jwtToken =
|
||||
'&token=' +
|
||||
jwt.sign({ username: usernameValue, password: passwordValue, presenter: presenterValue }, JWT_KEY, {
|
||||
expiresIn: expireValue,
|
||||
});
|
||||
}
|
||||
return (
|
||||
const joinURL =
|
||||
'https://' +
|
||||
this._host +
|
||||
'/join?room=' +
|
||||
roomValue +
|
||||
'&roomPassword=' +
|
||||
roomPasswordValue +
|
||||
'&name=' +
|
||||
nameValue +
|
||||
'&audio=' +
|
||||
audioValue +
|
||||
'&video=' +
|
||||
videoValue +
|
||||
'&screen=' +
|
||||
screenValue +
|
||||
'¬ify=' +
|
||||
notifyValue +
|
||||
jwtToken
|
||||
);
|
||||
'/join?' +
|
||||
`room=${roomValue}` +
|
||||
`&roomPassword=${roomPasswordValue}` +
|
||||
`&name=${encodeURIComponent(nameValue)}` +
|
||||
`&audio=${audioValue}` +
|
||||
`&video=${videoValue}` +
|
||||
`&screen=${screenValue}` +
|
||||
`¬ify=${notifyValue}` +
|
||||
jwtToken;
|
||||
|
||||
return joinURL;
|
||||
}
|
||||
|
||||
getToken(token) {
|
||||
if (!token) return '';
|
||||
|
||||
const { username = 'username', password = 'password', presenter = false, expire } = token;
|
||||
|
||||
const expireValue = expire || JWT_EXP;
|
||||
|
||||
const payload = {
|
||||
username: String(username),
|
||||
password: String(password),
|
||||
presenter: String(presenter),
|
||||
};
|
||||
|
||||
const jwtToken = jwt.sign(payload, JWT_KEY, { expiresIn: expireValue });
|
||||
|
||||
return jwtToken;
|
||||
}
|
||||
|
||||
getRandomNumber() {
|
||||
|
||||
@@ -219,6 +219,7 @@ module.exports = {
|
||||
meetings: false,
|
||||
meeting: true,
|
||||
join: true,
|
||||
token: true,
|
||||
//...
|
||||
},
|
||||
},
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم