2023-10-19 13:38:57 +00:00
|
|
|
import { Rocketchat as RocketchatClient } from '@rocket.chat/sdk';
|
2022-03-08 18:54:26 +00:00
|
|
|
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
|
|
|
import { InteractionManager } from 'react-native';
|
|
|
|
import { Q } from '@nozbe/watermelondb';
|
|
|
|
|
2022-06-06 14:17:51 +00:00
|
|
|
import log from '../methods/helpers/log';
|
2022-04-07 16:53:07 +00:00
|
|
|
import { setActiveUsers } from '../../actions/activeUsers';
|
|
|
|
import protectedFunction from '../methods/helpers/protectedFunction';
|
|
|
|
import database from '../database';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { twoFactor } from './twoFactor';
|
2022-04-07 16:53:07 +00:00
|
|
|
import { store } from '../store/auxStore';
|
|
|
|
import { loginRequest, setLoginServices, setUser } from '../../actions/login';
|
2022-03-08 18:54:26 +00:00
|
|
|
import sdk from './sdk';
|
2022-04-07 16:53:07 +00:00
|
|
|
import I18n from '../../i18n';
|
2022-05-13 14:52:37 +00:00
|
|
|
import { ICredentials, ILoggedUser, STATUSES } from '../../definitions';
|
2022-04-07 16:53:07 +00:00
|
|
|
import { connectRequest, connectSuccess, disconnect as disconnectAction } from '../../actions/connect';
|
|
|
|
import { updatePermission } from '../../actions/permissions';
|
2022-06-06 14:17:51 +00:00
|
|
|
import EventEmitter from '../methods/helpers/events';
|
2022-04-07 16:53:07 +00:00
|
|
|
import { updateSettings } from '../../actions/settings';
|
2023-10-19 13:38:57 +00:00
|
|
|
import { defaultSettings } from '../constants';
|
2023-02-14 13:47:56 +00:00
|
|
|
import {
|
|
|
|
getSettings,
|
|
|
|
IActiveUsers,
|
|
|
|
unsubscribeRooms,
|
|
|
|
_activeUsers,
|
|
|
|
_setUser,
|
|
|
|
_setUserTimer,
|
|
|
|
onRolesChanged,
|
|
|
|
setPresenceCap
|
|
|
|
} from '../methods';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { compareServerVersion, isIOS, isSsl } from '../methods/helpers';
|
2022-03-08 18:54:26 +00:00
|
|
|
|
|
|
|
interface IServices {
|
|
|
|
[index: string]: string | boolean;
|
|
|
|
name: string;
|
|
|
|
custom: boolean;
|
|
|
|
showButton: boolean;
|
|
|
|
buttonLabelText: string;
|
|
|
|
service: string;
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
let connectingListener: any;
|
|
|
|
let connectedListener: any;
|
|
|
|
let closeListener: any;
|
|
|
|
let usersListener: any;
|
|
|
|
let notifyAllListener: any;
|
|
|
|
let rolesListener: any;
|
|
|
|
let notifyLoggedListener: any;
|
|
|
|
|
2023-10-19 13:38:57 +00:00
|
|
|
function connect({ server, logoutOnError = false }: { server: string; logoutOnError?: boolean }): Promise<void> {
|
2022-03-08 18:54:26 +00:00
|
|
|
return new Promise<void>(resolve => {
|
|
|
|
if (sdk.current?.client?.host === server) {
|
|
|
|
return resolve();
|
|
|
|
}
|
2022-08-17 12:49:13 +00:00
|
|
|
|
|
|
|
// Check for running requests and abort them before connecting to the server
|
|
|
|
abort();
|
|
|
|
|
2022-03-08 18:54:26 +00:00
|
|
|
disconnect();
|
|
|
|
database.setActiveDB(server);
|
|
|
|
|
|
|
|
store.dispatch(connectRequest());
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
if (connectingListener) {
|
|
|
|
connectingListener.then(stopListener);
|
2022-03-08 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
if (connectedListener) {
|
|
|
|
connectedListener.then(stopListener);
|
2022-03-08 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
if (closeListener) {
|
|
|
|
closeListener.then(stopListener);
|
2022-03-08 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
if (usersListener) {
|
|
|
|
usersListener.then(stopListener);
|
2022-03-08 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
if (notifyAllListener) {
|
|
|
|
notifyAllListener.then(stopListener);
|
2022-03-08 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
if (rolesListener) {
|
|
|
|
rolesListener.then(stopListener);
|
2022-03-08 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
if (notifyLoggedListener) {
|
|
|
|
notifyLoggedListener.then(stopListener);
|
2022-03-08 18:54:26 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
unsubscribeRooms();
|
2022-03-08 18:54:26 +00:00
|
|
|
|
|
|
|
EventEmitter.emit('INQUIRY_UNSUBSCRIBE');
|
|
|
|
|
|
|
|
sdk.initialize(server);
|
2022-04-28 20:37:25 +00:00
|
|
|
getSettings();
|
2022-03-08 18:54:26 +00:00
|
|
|
|
|
|
|
sdk.current
|
|
|
|
.connect()
|
|
|
|
.then(() => {
|
|
|
|
console.log('connected');
|
|
|
|
})
|
|
|
|
.catch((err: unknown) => {
|
|
|
|
console.log('connect error', err);
|
|
|
|
});
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
connectingListener = sdk.current.onStreamData('connecting', () => {
|
2022-03-08 18:54:26 +00:00
|
|
|
store.dispatch(connectRequest());
|
|
|
|
});
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
connectedListener = sdk.current.onStreamData('connected', () => {
|
2022-03-08 18:54:26 +00:00
|
|
|
const { connected } = store.getState().meteor;
|
|
|
|
if (connected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
store.dispatch(connectSuccess());
|
2022-03-11 14:12:25 +00:00
|
|
|
const { user } = store.getState().login;
|
|
|
|
if (user?.token) {
|
2022-03-08 18:54:26 +00:00
|
|
|
store.dispatch(loginRequest({ resume: user.token }, logoutOnError));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
closeListener = sdk.current.onStreamData('close', () => {
|
2022-03-08 18:54:26 +00:00
|
|
|
store.dispatch(disconnectAction());
|
|
|
|
});
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
usersListener = sdk.current.onStreamData(
|
2022-03-08 18:54:26 +00:00
|
|
|
'users',
|
2022-05-13 14:52:37 +00:00
|
|
|
protectedFunction((ddpMessage: any) => _setUser(ddpMessage))
|
2022-03-08 18:54:26 +00:00
|
|
|
);
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
notifyAllListener = sdk.current.onStreamData(
|
2022-03-08 18:54:26 +00:00
|
|
|
'stream-notify-all',
|
|
|
|
protectedFunction(async (ddpMessage: { fields: { args?: any; eventName: string } }) => {
|
|
|
|
const { eventName } = ddpMessage.fields;
|
|
|
|
if (/public-settings-changed/.test(eventName)) {
|
|
|
|
const { _id, value } = ddpMessage.fields.args[1];
|
|
|
|
const db = database.active;
|
|
|
|
const settingsCollection = db.get('settings');
|
|
|
|
try {
|
|
|
|
const settingsRecord = await settingsCollection.find(_id);
|
|
|
|
// @ts-ignore
|
|
|
|
const { type } = defaultSettings[_id];
|
|
|
|
if (type) {
|
|
|
|
await db.write(async () => {
|
|
|
|
await settingsRecord.update(u => {
|
|
|
|
// @ts-ignore
|
|
|
|
u[type] = value;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
store.dispatch(updateSettings(_id, value));
|
2023-02-14 13:47:56 +00:00
|
|
|
|
|
|
|
if (_id === 'Presence_broadcast_disabled') {
|
|
|
|
setPresenceCap(value);
|
|
|
|
}
|
2022-03-08 18:54:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
rolesListener = sdk.current.onStreamData(
|
2022-03-08 18:54:26 +00:00
|
|
|
'stream-roles',
|
|
|
|
protectedFunction((ddpMessage: any) => onRolesChanged(ddpMessage))
|
|
|
|
);
|
|
|
|
|
|
|
|
// RC 4.1
|
|
|
|
sdk.current.onStreamData('stream-user-presence', (ddpMessage: { fields: { args?: any; uid?: any } }) => {
|
|
|
|
const userStatus = ddpMessage.fields.args[0];
|
|
|
|
const { uid } = ddpMessage.fields;
|
|
|
|
const [, status, statusText] = userStatus;
|
|
|
|
const newStatus = { status: STATUSES[status], statusText };
|
|
|
|
// @ts-ignore
|
|
|
|
store.dispatch(setActiveUsers({ [uid]: newStatus }));
|
|
|
|
|
|
|
|
const { user: loggedUser } = store.getState().login;
|
|
|
|
if (loggedUser && loggedUser.id === uid) {
|
|
|
|
// @ts-ignore
|
|
|
|
store.dispatch(setUser(newStatus));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-13 14:52:37 +00:00
|
|
|
notifyLoggedListener = sdk.current.onStreamData(
|
2022-03-08 18:54:26 +00:00
|
|
|
'stream-notify-logged',
|
|
|
|
protectedFunction(async (ddpMessage: { fields: { args?: any; eventName?: any } }) => {
|
|
|
|
const { eventName } = ddpMessage.fields;
|
|
|
|
|
|
|
|
// `user-status` event is deprecated after RC 4.1 in favor of `stream-user-presence/${uid}`
|
|
|
|
if (/user-status/.test(eventName)) {
|
2022-05-13 14:52:37 +00:00
|
|
|
_activeUsers.activeUsers = _activeUsers.activeUsers || {};
|
|
|
|
if (!_setUserTimer.setUserTimer) {
|
|
|
|
_setUserTimer.setUserTimer = setTimeout(() => {
|
|
|
|
const activeUsersBatch = _activeUsers.activeUsers;
|
2022-03-08 18:54:26 +00:00
|
|
|
InteractionManager.runAfterInteractions(() => {
|
2022-05-13 14:52:37 +00:00
|
|
|
// @ts-ignore
|
2022-03-08 18:54:26 +00:00
|
|
|
store.dispatch(setActiveUsers(activeUsersBatch));
|
|
|
|
});
|
2022-05-13 14:52:37 +00:00
|
|
|
_setUserTimer.setUserTimer = null;
|
|
|
|
_activeUsers.activeUsers = {} as IActiveUsers;
|
|
|
|
return null;
|
2022-03-08 18:54:26 +00:00
|
|
|
}, 10000);
|
|
|
|
}
|
|
|
|
const userStatus = ddpMessage.fields.args[0];
|
|
|
|
const [id, , status, statusText] = userStatus;
|
2022-05-13 14:52:37 +00:00
|
|
|
_activeUsers.activeUsers[id] = { status: STATUSES[status], statusText };
|
2022-03-08 18:54:26 +00:00
|
|
|
|
|
|
|
const { user: loggedUser } = store.getState().login;
|
|
|
|
if (loggedUser && loggedUser.id === id) {
|
2022-03-25 20:05:49 +00:00
|
|
|
store.dispatch(setUser({ status: STATUSES[status], statusText }));
|
2022-03-08 18:54:26 +00:00
|
|
|
}
|
|
|
|
} else if (/updateAvatar/.test(eventName)) {
|
|
|
|
const { username, etag } = ddpMessage.fields.args[0];
|
|
|
|
const db = database.active;
|
|
|
|
const userCollection = db.get('users');
|
|
|
|
try {
|
|
|
|
const [userRecord] = await userCollection.query(Q.where('username', Q.eq(username))).fetch();
|
|
|
|
await db.write(async () => {
|
|
|
|
await userRecord.update(u => {
|
|
|
|
u.avatarETag = etag;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
// We can't create a new record since we don't receive the user._id
|
|
|
|
}
|
|
|
|
} else if (/permissions-changed/.test(eventName)) {
|
|
|
|
const { _id, roles } = ddpMessage.fields.args[1];
|
|
|
|
const db = database.active;
|
|
|
|
const permissionsCollection = db.get('permissions');
|
|
|
|
try {
|
|
|
|
const permissionsRecord = await permissionsCollection.find(_id);
|
|
|
|
await db.write(async () => {
|
|
|
|
await permissionsRecord.update(u => {
|
|
|
|
u.roles = roles;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
store.dispatch(updatePermission(_id, roles));
|
|
|
|
} catch (err) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
} else if (/Users:NameChanged/.test(eventName)) {
|
|
|
|
const userNameChanged = ddpMessage.fields.args[0];
|
|
|
|
const db = database.active;
|
|
|
|
const userCollection = db.get('users');
|
|
|
|
try {
|
|
|
|
const userRecord = await userCollection.find(userNameChanged._id);
|
|
|
|
await db.write(async () => {
|
|
|
|
await userRecord.update(u => {
|
|
|
|
Object.assign(u, userNameChanged);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
// User not found
|
|
|
|
await db.write(async () => {
|
|
|
|
await userCollection.create(u => {
|
|
|
|
u._raw = sanitizedRaw({ id: userNameChanged._id }, userCollection.schema);
|
|
|
|
Object.assign(u, userNameChanged);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopListener(listener: any): boolean {
|
|
|
|
return listener && listener.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function login(credentials: ICredentials, isFromWebView = false): Promise<ILoggedUser | undefined> {
|
|
|
|
// RC 0.64.0
|
|
|
|
await sdk.current.login(credentials);
|
2022-07-06 15:43:50 +00:00
|
|
|
const serverVersion = store.getState().server.version;
|
2022-03-08 18:54:26 +00:00
|
|
|
const result = sdk.current.currentLogin?.result;
|
2022-07-06 15:43:50 +00:00
|
|
|
|
|
|
|
let enableMessageParserEarlyAdoption = true;
|
2022-08-25 19:53:19 +00:00
|
|
|
let showMessageInMainThread = false;
|
2022-07-06 15:43:50 +00:00
|
|
|
if (compareServerVersion(serverVersion, 'lowerThan', '5.0.0')) {
|
|
|
|
enableMessageParserEarlyAdoption = result.me.settings?.preferences?.enableMessageParserEarlyAdoption ?? true;
|
2022-08-25 19:53:19 +00:00
|
|
|
showMessageInMainThread = result.me.settings?.preferences?.showMessageInMainThread ?? true;
|
2022-07-06 15:43:50 +00:00
|
|
|
}
|
|
|
|
|
2022-03-08 18:54:26 +00:00
|
|
|
if (result) {
|
|
|
|
const user: ILoggedUser = {
|
|
|
|
id: result.userId,
|
|
|
|
token: result.authToken,
|
|
|
|
username: result.me.username,
|
|
|
|
name: result.me.name,
|
|
|
|
language: result.me.language,
|
|
|
|
status: result.me.status,
|
|
|
|
statusText: result.me.statusText,
|
|
|
|
customFields: result.me.customFields,
|
|
|
|
statusLivechat: result.me.statusLivechat,
|
|
|
|
emails: result.me.emails,
|
|
|
|
roles: result.me.roles,
|
|
|
|
avatarETag: result.me.avatarETag,
|
|
|
|
isFromWebView,
|
2022-08-25 19:53:19 +00:00
|
|
|
showMessageInMainThread,
|
|
|
|
enableMessageParserEarlyAdoption,
|
2023-08-01 17:34:05 +00:00
|
|
|
alsoSendThreadToChannel: result.me.settings?.preferences?.alsoSendThreadToChannel,
|
|
|
|
bio: result.me.bio,
|
|
|
|
nickname: result.me.nickname
|
2022-03-08 18:54:26 +00:00
|
|
|
};
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function loginTOTP(params: ICredentials, loginEmailPassword?: boolean, isFromWebView = false): Promise<ILoggedUser> {
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
try {
|
|
|
|
const result = await login(params, isFromWebView);
|
|
|
|
if (result) {
|
|
|
|
return resolve(result);
|
|
|
|
}
|
|
|
|
} catch (e: any) {
|
|
|
|
if (e.data?.error && (e.data.error === 'totp-required' || e.data.error === 'totp-invalid')) {
|
|
|
|
const { details } = e.data;
|
|
|
|
try {
|
|
|
|
const code = await twoFactor({ method: details?.method || 'totp', invalid: details?.error === 'totp-invalid' });
|
|
|
|
|
|
|
|
if (loginEmailPassword) {
|
|
|
|
store.dispatch(setUser({ username: params.user || params.username }));
|
|
|
|
|
|
|
|
// Force normalized params for 2FA starting RC 3.9.0.
|
|
|
|
const serverVersion = store.getState().server.version;
|
|
|
|
if (compareServerVersion(serverVersion as string, 'greaterThanOrEqualTo', '3.9.0')) {
|
|
|
|
const user = params.user ?? params.username;
|
|
|
|
const password = params.password ?? params.ldapPass ?? params.crowdPassword;
|
|
|
|
params = { user, password };
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(loginTOTP({ ...params, code: code?.twoFactorCode }, loginEmailPassword));
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve(
|
|
|
|
loginTOTP({
|
|
|
|
totp: {
|
|
|
|
login: {
|
|
|
|
...params
|
|
|
|
},
|
|
|
|
code: code?.twoFactorCode
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} catch {
|
|
|
|
// twoFactor was canceled
|
|
|
|
return reject();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
reject(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function loginWithPassword({ user, password }: { user: string; password: string }): Promise<ILoggedUser> {
|
|
|
|
let params: ICredentials = { user, password };
|
|
|
|
const state = store.getState();
|
|
|
|
|
|
|
|
if (state.settings.LDAP_Enable) {
|
|
|
|
params = {
|
|
|
|
username: user,
|
|
|
|
ldapPass: password,
|
|
|
|
ldap: true,
|
|
|
|
ldapOptions: {}
|
|
|
|
};
|
|
|
|
} else if (state.settings.CROWD_Enable) {
|
|
|
|
params = {
|
|
|
|
username: user,
|
|
|
|
crowdPassword: password,
|
|
|
|
crowd: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return loginTOTP(params, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loginOAuthOrSso(params: ICredentials, isFromWebView = true) {
|
|
|
|
const result = await loginTOTP(params, false, isFromWebView);
|
|
|
|
store.dispatch(loginRequest({ resume: result.token }, false, isFromWebView));
|
|
|
|
}
|
|
|
|
|
|
|
|
function abort() {
|
|
|
|
if (sdk.current) {
|
|
|
|
return sdk.current.abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAndReopen() {
|
|
|
|
return sdk.current.checkAndReopen();
|
|
|
|
}
|
|
|
|
|
|
|
|
function disconnect() {
|
|
|
|
return sdk.disconnect();
|
|
|
|
}
|
|
|
|
|
2023-10-19 13:38:57 +00:00
|
|
|
async function getWebsocketInfo({
|
|
|
|
server
|
|
|
|
}: {
|
|
|
|
server: string;
|
|
|
|
}): Promise<{ success: true } | { success: false; message: string }> {
|
2022-05-19 16:43:49 +00:00
|
|
|
const websocketSdk = new RocketchatClient({ host: server, protocol: 'ddp', useSsl: isSsl(server) });
|
2022-03-08 18:54:26 +00:00
|
|
|
|
|
|
|
try {
|
2022-05-19 16:43:49 +00:00
|
|
|
await websocketSdk.connect();
|
2022-03-08 18:54:26 +00:00
|
|
|
} catch (err: any) {
|
|
|
|
if (err.message && err.message.includes('400')) {
|
|
|
|
return {
|
|
|
|
success: false,
|
|
|
|
message: I18n.t('Websocket_disabled', { contact: I18n.t('Contact_your_server_admin') })
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-19 16:43:49 +00:00
|
|
|
websocketSdk.disconnect();
|
2022-03-08 18:54:26 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
success: true
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getLoginServices(server: string) {
|
|
|
|
try {
|
|
|
|
let loginServices = [];
|
|
|
|
const loginServicesResult = await fetch(`${server}/api/v1/settings.oauth`).then(response => response.json());
|
|
|
|
|
|
|
|
if (loginServicesResult.success && loginServicesResult.services) {
|
|
|
|
const { services } = loginServicesResult;
|
|
|
|
loginServices = services;
|
|
|
|
|
|
|
|
const loginServicesReducer = loginServices.reduce((ret: IServices[], item: IServices) => {
|
|
|
|
const name = item.name || item.buttonLabelText || item.service;
|
|
|
|
const authType = determineAuthType(item);
|
|
|
|
|
|
|
|
if (authType !== 'not_supported') {
|
|
|
|
ret[name as unknown as number] = { ...item, name, authType };
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}, {});
|
|
|
|
store.dispatch(setLoginServices(loginServicesReducer));
|
|
|
|
} else {
|
|
|
|
store.dispatch(setLoginServices({}));
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
store.dispatch(setLoginServices({}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function determineAuthType(services: IServices) {
|
|
|
|
const { name, custom, showButton = true, service } = services;
|
|
|
|
|
|
|
|
const authName = name || service;
|
|
|
|
|
|
|
|
if (custom && showButton) {
|
|
|
|
return 'oauth_custom';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (service === 'saml') {
|
|
|
|
return 'saml';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (service === 'cas') {
|
|
|
|
return 'cas';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (authName === 'apple' && isIOS) {
|
|
|
|
return 'apple';
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove this after other oauth providers are implemented. e.g. Drupal, github_enterprise
|
|
|
|
const availableOAuth = ['facebook', 'github', 'gitlab', 'google', 'linkedin', 'meteor-developer', 'twitter', 'wordpress'];
|
|
|
|
return availableOAuth.includes(authName) ? 'oauth' : 'not_supported';
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
login,
|
|
|
|
loginTOTP,
|
|
|
|
loginWithPassword,
|
|
|
|
loginOAuthOrSso,
|
|
|
|
checkAndReopen,
|
|
|
|
abort,
|
|
|
|
connect,
|
|
|
|
disconnect,
|
|
|
|
getWebsocketInfo,
|
|
|
|
stopListener,
|
|
|
|
getLoginServices,
|
|
|
|
determineAuthType
|
|
|
|
};
|