The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/tokenpass/server/startup.js

39 lines
1.4 KiB

import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { updateUserTokenpassBalances } from './functions/updateUserTokenpassBalances';
import { settings } from '../../settings';
import { callbacks } from '../../callbacks';
import { validateTokenAccess } from './roomAccessValidator.compatibility';
import './roomAccessValidator.internalService';
settings.addGroup('OAuth', function() {
this.section('Tokenpass', function() {
const enableQuery = {
_id: 'Accounts_OAuth_Tokenpass',
value: true,
};
this.add('Accounts_OAuth_Tokenpass', false, { type: 'boolean' });
this.add('API_Tokenpass_URL', '', { type: 'string', public: true, enableQuery, i18nDescription: 'API_Tokenpass_URL_Description' });
this.add('Accounts_OAuth_Tokenpass_id', '', { type: 'string', enableQuery });
this.add('Accounts_OAuth_Tokenpass_secret', '', { type: 'string', enableQuery });
this.add('Accounts_OAuth_Tokenpass_callback_url', '_oauth/tokenpass', { type: 'relativeUrl', readonly: true, force: true, enableQuery });
});
});
Meteor.startup(function() {
callbacks.add('beforeJoinRoom', function(user, room) {
if (room.tokenpass && !validateTokenAccess(user, room)) {
throw new Meteor.Error('error-not-allowed', 'Token required', { method: 'joinRoom' });
}
return user;
});
});
Accounts.onLogin(function({ user }) {
if (user && user.services && user.services.tokenpass) {
updateUserTokenpassBalances(user);
}
});