2017-02-07 23:29:27 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2017-10-12 10:00:28 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2017-02-07 23:29:27 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-09-01 20:07:56 +08:00
|
|
|
import upsertValidationState from '/imports/api/auth-token-validation/server/modifiers/upsertValidationState';
|
|
|
|
import { ValidationStates } from '/imports/api/auth-token-validation';
|
2020-09-02 00:31:11 +08:00
|
|
|
import pendingAuthenticationsStore from '../store/pendingAuthentications';
|
|
|
|
import BannedUsers from '../store/bannedUsers';
|
2017-02-07 23:29:27 +08:00
|
|
|
|
2020-06-13 00:24:11 +08:00
|
|
|
export default function validateAuthToken(meetingId, requesterUserId, requesterToken, externalId) {
|
2018-01-08 08:24:05 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
2017-10-12 09:02:23 +08:00
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'ValidateAuthTokenReqMsg';
|
2017-02-07 23:29:27 +08:00
|
|
|
|
2021-01-30 01:27:13 +08:00
|
|
|
Logger.debug('ValidateAuthToken method called', { meetingId, requesterUserId, requesterToken, externalId });
|
|
|
|
|
2020-06-13 00:24:11 +08:00
|
|
|
// Check if externalId is banned from the meeting
|
2020-06-13 03:51:22 +08:00
|
|
|
if (externalId) {
|
|
|
|
if (BannedUsers.has(meetingId, externalId)) {
|
|
|
|
Logger.warn(`A banned user with extId ${externalId} tried to enter in meeting ${meetingId}`);
|
2020-10-16 21:30:50 +08:00
|
|
|
return { invalid: true, reason: 'User has been banned', error_type: 'user_banned' };
|
2020-06-13 03:51:22 +08:00
|
|
|
}
|
|
|
|
}
|
2020-06-13 00:24:11 +08:00
|
|
|
|
2021-01-27 03:22:32 +08:00
|
|
|
if (!meetingId) return false;
|
2020-09-01 20:07:56 +08:00
|
|
|
|
2020-04-29 11:33:45 +08:00
|
|
|
// Store reference of methodInvocationObject ( to postpone the connection userId definition )
|
|
|
|
pendingAuthenticationsStore.add(meetingId, requesterUserId, requesterToken, this);
|
2020-09-01 20:07:56 +08:00
|
|
|
upsertValidationState(meetingId, requesterUserId, ValidationStates.VALIDATING, this.connection.id);
|
2018-02-20 22:21:51 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const payload = {
|
2017-10-12 09:02:23 +08:00
|
|
|
userId: requesterUserId,
|
|
|
|
authToken: requesterToken,
|
2017-02-07 23:29:27 +08:00
|
|
|
};
|
|
|
|
|
2020-04-29 11:33:45 +08:00
|
|
|
Logger.info(`User '${requesterUserId}' is trying to validate auth token for meeting '${meetingId}' from connection '${this.connection.id}'`);
|
2017-02-07 23:29:27 +08:00
|
|
|
|
2017-10-12 09:02:23 +08:00
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|