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
40 changes: 28 additions & 12 deletions apps/meteor/app/drupal/server/lib.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type { OauthConfig } from '@rocket.chat/core-typings';
import type { OAuthConfiguration } from '@rocket.chat/core-typings';
import { Meteor } from 'meteor/meteor';
import passport from 'passport';
import _ from 'underscore';

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

// Drupal Server CallBack URL needs to be http(s)://{rocketchat.server}[:port]/_oauth/drupal
// In RocketChat -> Administration the URL needs to be http(s)://{drupal.server}/

const config: OauthConfig = {
serverURL: '',
const config: Partial<OAuthConfiguration> = {
identityPath: '/oauth2/UserInfo',
authorizePath: '/oauth2/authorize',
tokenPath: '/oauth2/token',
Expand All @@ -23,11 +21,29 @@ const config: OauthConfig = {
accessTokenParam: 'access_token',
};

const Drupal = new CustomOAuth('drupal', config);
const configureDrupalOAuth = () => {
passport.unuse('drupal');
const enabled = settings.get<boolean>('Accounts_OAuth_Drupal');
if (!enabled) {
return;
}

const serverURL = settings.get<string>('API_Drupal_URL').trim().replace(/\/*$/, '');
Comment thread
yash-rajpal marked this conversation as resolved.
const clientId = settings.get<string>('Accounts_OAuth_Drupal_id');
const clientSecret = settings.get<string>('Accounts_OAuth_Drupal_secret');

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

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

Meteor.startup(() => {
settings.watch<string>('API_Drupal_URL', (value) => {
config.serverURL = value;
Drupal.configure(config);
});
const updateConfig = _.debounce(configureDrupalOAuth, 300);

settings.watchMultiple(
['Accounts_OAuth_Drupal', 'API_Drupal_URL', 'Accounts_OAuth_Drupal_id', 'Accounts_OAuth_Drupal_secret'],
updateConfig,
);
});
Loading