forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* clean integration and rebase of RocketChat#12259
- Loading branch information
Showing
9 changed files
with
139 additions
and
7 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
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
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
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
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
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
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
56 changes: 56 additions & 0 deletions
56
packages/rocketchat-videobridge/server/methods/jitsiGenerateToken.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,56 @@ | ||
// we need only jws functionality | ||
import { jws } from 'jsrsasign'; | ||
|
||
Meteor.methods({ | ||
'jitsi:generateAccessToken': () => { | ||
|
||
if (!Meteor.userId()) { | ||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'jitsi:generateToken' }); | ||
} | ||
|
||
const jitsiDomain = RocketChat.settings.get('Jitsi_Domain'); | ||
const jitsiApplicationId = RocketChat.settings.get('Jitsi_Application_ID'); | ||
const jitsiApplicationSecret = RocketChat.settings.get('Jitsi_Application_Secret'); | ||
|
||
function addUserContextToPayload(payload) { | ||
const user = Meteor.user(); | ||
payload.context = { | ||
user: { | ||
name: user.name, | ||
email: user.emails[0].address, | ||
avatar: Meteor.absoluteUrl(`avatar/${ user.username }`), | ||
id: user._id, | ||
}, | ||
}; | ||
return payload; | ||
} | ||
|
||
const JITSI_OPTIONS = { | ||
jitsi_domain: jitsiDomain, | ||
jitsi_lifetime_token: '1hour', // only 1 hour (for security reasons) | ||
jitsi_application_id: jitsiApplicationId, | ||
jitsi_application_secret: jitsiApplicationSecret, | ||
}; | ||
|
||
const HEADER = { | ||
typ: 'JWT', | ||
alg: 'HS256', | ||
}; | ||
|
||
const commonPayload = { | ||
iss: JITSI_OPTIONS.jitsi_application_id, | ||
sub: JITSI_OPTIONS.jitsi_domain, | ||
iat: jws.IntDate.get('now'), | ||
nbf: jws.IntDate.get('now'), | ||
exp: jws.IntDate.get(`now + ${ JITSI_OPTIONS.jitsi_lifetime_token }`), | ||
aud: 'RocketChat', | ||
room: '*', | ||
context: '', // first empty | ||
}; | ||
|
||
const header = JSON.stringify(HEADER); | ||
const payload = JSON.stringify(addUserContextToPayload(commonPayload)); | ||
|
||
return jws.JWS.sign(HEADER.alg, header, payload, { rstr: JITSI_OPTIONS.jitsi_application_secret }); | ||
}, | ||
}); |
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