From 5224d904e71ae66ef8d5ce27a837bced12d87ab1 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Tue, 19 May 2026 19:33:17 +0530 Subject: [PATCH] drupal custom passport OAuth --- apps/meteor/app/drupal/server/lib.ts | 40 +++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/apps/meteor/app/drupal/server/lib.ts b/apps/meteor/app/drupal/server/lib.ts index d137551fb8377..a4f71bd81696f 100644 --- a/apps/meteor/app/drupal/server/lib.ts +++ b/apps/meteor/app/drupal/server/lib.ts @@ -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 = { identityPath: '/oauth2/UserInfo', authorizePath: '/oauth2/authorize', tokenPath: '/oauth2/token', @@ -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('Accounts_OAuth_Drupal'); + if (!enabled) { + return; + } + + const serverURL = settings.get('API_Drupal_URL').trim().replace(/\/*$/, ''); + const clientId = settings.get('Accounts_OAuth_Drupal_id'); + const clientSecret = settings.get('Accounts_OAuth_Drupal_secret'); + + if (!clientId || !clientSecret || !serverURL) { + return; + } + + addPassportCustomOAuth('drupal', { ...config, serverURL, clientId, clientSecret }); +}; Meteor.startup(() => { - settings.watch('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, + ); });