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
26 changes: 11 additions & 15 deletions apps/meteor/app/wordpress/server/lib.ts
Original file line number Diff line number Diff line change
@@ -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<OAuthConfiguration> = {
serverURL: '',
identityPath: '/oauth/me',

Expand All @@ -17,7 +18,7 @@ const config: OauthConfig = {
accessTokenParam: 'access_token',
};

const WordPress = new CustomOAuth('wordpress', config);
const serviceKey = 'wordpress';

const fillSettings = _.debounce(async (): Promise<void> => {
config.serverURL = settings.get('API_Wordpress_URL');
Expand All @@ -28,11 +29,7 @@ const fillSettings = _.debounce(async (): Promise<void> => {
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) {
Expand All @@ -59,7 +56,7 @@ const fillSettings = _.debounce(async (): Promise<void> => {
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';
Expand All @@ -69,24 +66,23 @@ const fillSettings = _.debounce(async (): Promise<void> => {
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,
},
);
} else {
await ServiceConfiguration.configurations.removeAsync({
service: 'wordpress',
service: serviceKey,
});
}

return result;
}, 1000);

Meteor.startup(() => {
Expand Down
Loading