Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static parse(plain: Response): ?Session {
const token = plain.data.metadata ? plain.data.metadata.jwt : null;
let authorizations = [];
// Add authorizations from JWT
if (token) {
const isValid = jws.JWS.verifyJWT(token, swarmKey, { alg: ['RS256'], verifyAt: new Date() });
if (isValid) {
const decodedToken = jws.JWS.readSafeJSONString(b64utoutf8(token.split('.')[1]));
authorizations = decodedToken ? decodedToken.authorizations : [];
}
}
return new Session({
token: plain.data.token,
refreshToken: plain.data.refresh_token || null,
uuid: plain.data.metadata ? plain.data.metadata.uuid : null,
sessionUuid: plain.data.session_uuid,
authorizations,
tenantUuid: plain.data.metadata ? plain.data.metadata.tenant_uuid : undefined,
expiresAt: new Date(`${plain.data.utc_expires_at}z`),
});
}
this.paramsSub = this._route.params.subscribe(params => {
this.consumerType = params['consumerType'];
this.code = this._route.snapshot.queryParams.code || this._route.snapshot.queryParams.token;
this.state = this._route.snapshot.queryParams.state || this._route.snapshot.queryParams.request;
if (!this.code || !this.state) {
this.loading = false;
this.missingParams = true;
this._cd.markForCheck();
return;
}
// If the origin is cdsctl, show the code and the state for copy
let payload = jws.JWS.parse(this.state).payloadObj;
if (payload.data) {
this.payloadData = JSON.parse(payload.data);
}
if (this.payloadData && this.payloadData.origin === 'cdsctl') {
this.loading = false;
this.showCTL = true;
this._cd.markForCheck();
return;
}
// If the first connection flag is set, show init token form
if (this.payloadData && this.payloadData.is_first_connection) {
this.loading = false;
this.showInitTokenForm = true;
this._cd.markForCheck();
return;
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 });
},
});