Permalink
Show file tree
Hide file tree
51 changes: 50 additions & 1 deletion
51
bigbluebutton-html5/imports/api/users/server/handlers/validateAuthToken.js
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Refactor connection definition of userId to wait for validateAuthToken
- Loading branch information
1 parent
1a2d0ae
commit 4bfd924
Showing
3 changed files
with
97 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 4 additions & 17 deletions
21
bigbluebutton-html5/imports/api/users/server/methods/validateAuthToken.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,22 @@ | ||
| 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'; | ||
| import pendingAuthenticationsStore from '../store/pendingAuthentications'; | ||
|
|
||
| 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); | ||
| // Store reference of methodInvocationObject ( to postpone the connection userId definition ) | ||
| pendingAuthenticationsStore.add(meetingId, requesterUserId, requesterToken, this); | ||
|
|
||
| const payload = { | ||
| userId: requesterUserId, | ||
| authToken: requesterToken, | ||
| }; | ||
|
|
||
| Logger.info(`User '${requesterUserId}' is trying to validate auth token for meeting '${meetingId}'`); | ||
| Logger.info(`User '${requesterUserId}' is trying to validate auth token for meeting '${meetingId}' from connection '${this.connection.id}'`); | ||
|
|
||
| return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload); | ||
| } |
43 changes: 43 additions & 0 deletions
43
bigbluebutton-html5/imports/api/users/server/store/pendingAuthentications.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import Logger from '/imports/startup/server/logger'; | ||
|
|
||
| class PendingAuthentitcations { | ||
| constructor () { | ||
| Logger.debug("PendingAuthentitcations :: constructor"); | ||
| this.store = []; | ||
| } | ||
|
|
||
| generateKey (meetingId, userId, authToken) { | ||
| // Protect against separator injection | ||
| meetingId = meetingId.replace(/ /g, ''); | ||
| userId = userId.replace(/ /g, ''); | ||
| authToken = authToken.replace(/ /g, ''); | ||
|
|
||
| // Space separated key | ||
| return '${meetingId} ${userId} ${authToken}'; | ||
| } | ||
|
|
||
| add (meetingId, userId, authToken, methodInvocationObject) { | ||
| Logger.debug("PendingAuthentitcations :: add", {meetingId, userId, authToken}); | ||
| this.store.push({ | ||
| key: this.generateKey(meetingId, userId, authToken), | ||
| meetingId, userId, authToken, methodInvocationObject | ||
| }); | ||
| } | ||
|
|
||
| take (meetingId, userId, authToken) { | ||
| Logger.debug("PendingAuthentitcations :: take", {meetingId, userId, authToken}); | ||
| const key = this.generateKey(meetingId, userId, authToken); | ||
|
|
||
| // find matches | ||
| const matches = this.store.filter( e => e.key === key ); | ||
|
|
||
| // remove matches (if any) | ||
| if(matches.length) { | ||
| this.store = this.store.filter( e => e.key !== key ) ; | ||
| } | ||
|
|
||
| // return matches | ||
| return matches; | ||
| } | ||
| } | ||
| export default new PendingAuthentitcations(); |