bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/methods/validateAuthToken.js

36 lines
1.2 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import createDummyUser from '../modifiers/createDummyUser';
import setConnectionIdAndAuthToken from '../modifiers/setConnectionIdAndAuthToken';
export default function validateAuthToken(meetingId, requesterUserId, requesterToken) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'ValidateAuthTokenReqMsg';
const sessionId = `${meetingId}--${requesterUserId}`;
this.setUserId(sessionId);
const User = Users.findOne({
meetingId,
userId: requesterUserId,
});
if (!User) {
createDummyUser(meetingId, requesterUserId, requesterToken);
}
setConnectionIdAndAuthToken(meetingId, requesterUserId, this.connection.id, requesterToken);
const payload = {
userId: requesterUserId,
authToken: requesterToken,
};
Logger.info(`User '${requesterUserId}' is trying to validate auth token for meeting '${meetingId}'`);
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
}