bigbluebutton-Github/bigbluebutton-html5/imports/ui/services/auth/index.js

242 lines
5.8 KiB
JavaScript
Raw Normal View History

/* eslint prefer-promise-reject-errors: 0 */
2017-03-11 02:33:46 +08:00
import { Tracker } from 'meteor/tracker';
2016-07-07 20:50:32 +08:00
import Storage from '/imports/ui/services/storage/session';
2017-03-11 02:33:46 +08:00
// import allowRedirectToLogoutURL from '/imports/ui/components/meeting-ended/service';
2023-01-19 22:32:00 +08:00
import logger from '/imports/startup/client/logger';
import { makeVar } from '@apollo/client';
const CONNECTION_TIMEOUT = window.meetingClientSettings.public.app.connectionTimeout;
class Auth {
constructor() {
this._loggedIn = {
value: false,
tracker: new Tracker.Dependency(),
};
const queryParams = new URLSearchParams(document.location.search);
if (queryParams.has('sessionToken')
&& queryParams.get('sessionToken') !== Session.get('sessionToken')) {
return;
}
this._meetingID = Storage.getItem('meetingID');
this._userID = Storage.getItem('userID');
this._authToken = Storage.getItem('authToken');
this._sessionToken = makeVar(Storage.getItem('sessionToken'));
2017-07-15 00:59:02 +08:00
this._logoutURL = Storage.getItem('logoutURL');
2018-06-20 00:46:59 +08:00
this._confname = Storage.getItem('confname');
this._externUserID = Storage.getItem('externUserID');
this._fullname = Storage.getItem('fullname');
this._connectionID = Storage.getItem('connectionID');
}
get meetingID() {
return this._meetingID;
}
set meetingID(meetingID) {
this._meetingID = meetingID;
Storage.setItem('meetingID', this._meetingID);
}
set _connectionID(connectionId) {
this._connectionID = connectionId;
Storage.setItem('sessionToken', this._connectionID);
}
get sessionToken() {
try {
return this._sessionToken();
} catch {
return null;
}
}
2017-07-19 20:44:47 +08:00
set sessionToken(sessionToken) {
if (this._sessionToken) {
this._sessionToken(sessionToken);
} else {
this._sessionToken = makeVar(sessionToken);
}
Storage.setItem('sessionToken', this._sessionToken());
2017-07-19 20:44:47 +08:00
}
get userID() {
return this._userID;
}
set userID(userID) {
this._userID = userID;
Storage.setItem('userID', this._userID);
}
2016-06-18 06:15:11 +08:00
get token() {
return this._authToken;
2016-06-25 07:09:32 +08:00
}
2016-06-18 06:15:11 +08:00
set token(authToken) {
this._authToken = authToken;
Storage.setItem('authToken', this._authToken);
}
2017-07-15 00:59:02 +08:00
set logoutURL(logoutURL) {
this._logoutURL = logoutURL;
Storage.setItem('logoutURL', this._logoutURL);
}
get logoutURL() {
return this._logoutURL;
}
2018-06-20 00:46:59 +08:00
set confname(confname) {
this._confname = confname;
Storage.setItem('confname', this._confname);
}
get confname() {
return this._confname;
}
set externUserID(externUserID) {
this._externUserID = externUserID;
Storage.setItem('externUserID', this._externUserID);
}
get externUserID() {
return this._externUserID;
}
set fullname(fullname) {
this._fullname = fullname;
Storage.setItem('fullname', this._fullname);
}
get fullname() {
return this._fullname;
}
2017-03-10 03:50:21 +08:00
get loggedIn() {
2017-03-11 02:33:46 +08:00
this._loggedIn.tracker.depend();
return this._loggedIn.value;
2017-03-10 03:50:21 +08:00
}
2017-03-11 02:33:46 +08:00
set loggedIn(value) {
this._loggedIn.value = value;
this._loggedIn.tracker.changed();
}
get credentials() {
return {
meetingId: this.meetingID,
requesterUserId: this.userID,
requesterToken: this.token,
2017-07-15 00:59:02 +08:00
logoutURL: this.logoutURL,
2017-07-19 20:44:47 +08:00
sessionToken: this.sessionToken,
2018-06-20 00:46:59 +08:00
fullname: this.fullname,
externUserID: this.externUserID,
2018-08-14 03:52:44 +08:00
confname: this.confname,
2018-06-20 00:46:59 +08:00
};
}
get fullInfo() {
return {
sessionToken: this.sessionToken,
meetingId: this.meetingID,
requesterUserId: this.userID,
fullname: this.fullname,
confname: this.confname,
externUserID: this.externUserID,
uniqueClientSession: this.uniqueClientSession,
};
}
2018-12-11 01:05:17 +08:00
set(
meetingId,
requesterUserId,
requesterToken,
logoutURL,
sessionToken,
fullname,
externUserID,
confname,
) {
2017-04-27 03:56:29 +08:00
this.meetingID = meetingId;
this.userID = requesterUserId;
this.token = requesterToken;
2017-07-15 00:59:02 +08:00
this.logoutURL = logoutURL;
2017-07-19 20:44:47 +08:00
this.sessionToken = sessionToken;
2018-06-20 00:46:59 +08:00
this.fullname = fullname;
this.externUserID = externUserID;
this.confname = confname;
2017-04-27 03:56:29 +08:00
}
2017-07-15 00:59:02 +08:00
clearCredentials(...args) {
this.meetingID = null;
this.userID = null;
this.token = null;
this.loggedIn = false;
2017-07-15 00:59:02 +08:00
this.logoutURL = null;
2017-07-19 20:44:47 +08:00
this.sessionToken = null;
2018-06-20 00:46:59 +08:00
this.fullname = null;
2018-08-14 03:52:44 +08:00
this.externUserID = null;
2018-06-20 00:46:59 +08:00
this.confname = null;
this.uniqueClientSession = null;
2017-07-15 00:59:02 +08:00
return Promise.resolve(...args);
2017-06-03 03:25:02 +08:00
}
logout() {
if (!this.loggedIn) {
if (allowRedirectToLogoutURL()) {
return Promise.resolve(this._logoutURL);
}
return Promise.resolve();
}
2017-07-15 00:59:02 +08:00
return new Promise((resolve) => {
if (allowRedirectToLogoutURL()) {
resolve(this._logoutURL);
}
// do not redirect
resolve();
});
2017-06-03 03:25:02 +08:00
}
allowRedirectToLogoutURL() {
const ALLOW_DEFAULT_LOGOUT_URL = window.meetingClientSettings.public.app.allowDefaultLogoutUrl;
const protocolPattern = /^((http|https):\/\/)/;
if (this.logoutURL) {
// default logoutURL
// compare only the host to ignore protocols
const urlWithoutProtocolForAuthLogout = this.logoutURL.replace(protocolPattern, '');
const urlWithoutProtocolForLocationOrigin = window.location.origin.replace(protocolPattern, '');
if (urlWithoutProtocolForAuthLogout === urlWithoutProtocolForLocationOrigin) {
return ALLOW_DEFAULT_LOGOUT_URL;
}
// custom logoutURL
return true;
}
// no logout url
return false;
}
authenticateURL(url) {
let authURL = url;
if (authURL.indexOf('sessionToken=') === -1) {
if (authURL.indexOf('?') !== -1) {
authURL = `${authURL}&sessionToken=${this.sessionToken}`;
} else {
authURL = `${authURL}?sessionToken=${this.sessionToken}`;
}
}
return authURL;
}
2017-06-03 03:25:02 +08:00
}
2016-06-29 02:50:44 +08:00
2017-06-03 03:25:02 +08:00
const AuthSingleton = new Auth();
export default AuthSingleton;