diff --git a/apps/meteor/app/wordpress/server/lib.ts b/apps/meteor/app/wordpress/server/lib.ts index 7777ea1382215..eb1ce2c01ceb2 100644 --- a/apps/meteor/app/wordpress/server/lib.ts +++ b/apps/meteor/app/wordpress/server/lib.ts @@ -1,12 +1,13 @@ -import type { OauthConfig } from '@rocket.chat/core-typings'; +import type { 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 { CustomOAuth } from '../../custom-oauth/server/custom_oauth_server'; +import { addPassportCustomOAuth } from '../../../server/lib/oauth/addPassportCustomOAuth'; import { settings } from '../../settings/server'; -const config: OauthConfig = { +const config: Partial = { serverURL: '', identityPath: '/oauth/me', @@ -17,7 +18,7 @@ const config: OauthConfig = { accessTokenParam: 'access_token', }; -const WordPress = new CustomOAuth('wordpress', config); +const serviceKey = 'wordpress'; const fillSettings = _.debounce(async (): Promise => { config.serverURL = settings.get('API_Wordpress_URL'); @@ -28,11 +29,7 @@ const fillSettings = _.debounce(async (): Promise => { return; } - delete config.identityPath; - delete config.identityTokenSentVia; - delete config.authorizePath; - delete config.tokenPath; - delete config.scope; + passport.unuse(serviceKey); const serverType = settings.get('Accounts_OAuth_Wordpress_server_type'); switch (serverType) { @@ -59,7 +56,7 @@ const fillSettings = _.debounce(async (): Promise => { break; case 'wordpress-com': config.identityPath = 'https://public-api.wordpress.com/rest/v1/me'; - config.identityTokenSentVia = 'header'; + config.identityTokenSentVia = 'header' as OAuthConfiguration['identityTokenSentVia']; config.authorizePath = 'https://public-api.wordpress.com/oauth2/authorize'; config.tokenPath = 'https://public-api.wordpress.com/oauth2/token'; config.scope = 'auth'; @@ -69,12 +66,13 @@ const fillSettings = _.debounce(async (): Promise => { break; } - const result = WordPress.configure(config); + addPassportCustomOAuth(serviceKey, config); + const enabled = settings.get('Accounts_OAuth_Wordpress'); if (enabled) { await ServiceConfiguration.configurations.upsertAsync( { - service: 'wordpress', + service: serviceKey, }, { $set: config, @@ -82,11 +80,9 @@ const fillSettings = _.debounce(async (): Promise => { ); } else { await ServiceConfiguration.configurations.removeAsync({ - service: 'wordpress', + service: serviceKey, }); } - - return result; }, 1000); Meteor.startup(() => {