Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions apps/meteor/app/dolphin/server/lib.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { IUser } from '@rocket.chat/core-typings';
import type { IUser, OAuthConfiguration } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';
import { ServiceConfiguration } from 'meteor/service-configuration';
import passport from 'passport';
import _ from 'underscore';

import { callbacks } from '../../../server/lib/callbacks';
import { beforeCreateUserCallback } from '../../../server/lib/callbacks/beforeCreateUserCallback';
import { CustomOAuth } from '../../custom-oauth/server/custom_oauth_server';
import { addPassportCustomOAuth } from '../../../server/lib/oauth/addPassportCustomOAuth';
import { settings } from '../../settings/server';

const config = {
const config: Partial<OAuthConfiguration> = {
serverURL: '',
authorizePath: '/m/oauth2/auth/',
tokenPath: '/m/oauth2/token/',
Expand All @@ -20,8 +22,6 @@ const config = {
accessTokenParam: 'access_token',
};

const Dolphin = new CustomOAuth('dolphin', config);

function DolphinOnCreateUser(options: any, user?: IUser) {
// TODO: callbacks Fix this
if (user?.services?.dolphin?.NickName) {
Expand All @@ -30,11 +30,32 @@ function DolphinOnCreateUser(options: any, user?: IUser) {
return options;
}

const configureDolphinOAuth = () => {
passport.unuse('dolphin');

const enabled = settings.get<boolean>('Accounts_OAuth_Dolphin');
if (!enabled) {
return;
}

const serverURL = settings.get<string>('Accounts_OAuth_Dolphin_URL').trim().replace(/\/*$/, '');
const clientId = settings.get<string>('Accounts_OAuth_Dolphin_id');
const clientSecret = settings.get<string>('Accounts_OAuth_Dolphin_secret');

if (!clientId || !clientSecret || !serverURL) {
return;
}

addPassportCustomOAuth('dolphin', { ...config, serverURL, clientId, clientSecret });
};

Meteor.startup(async () => {
settings.watch<string>('Accounts_OAuth_Dolphin_URL', (value) => {
config.serverURL = value;
return Dolphin.configure(config);
});
const updateConfig = () => _.debounce(configureDolphinOAuth, 300);

settings.watchMultiple(
['Accounts_OAuth_Dolphin', 'Accounts_OAuth_Dolphin_URL', 'Accounts_OAuth_Dolphin_id', 'Accounts_OAuth_Dolphin_secret'],
updateConfig,
);

if (settings.get('Accounts_OAuth_Dolphin_URL')) {
const data = {
Expand Down
Loading