diff --git a/packages/rocketchat-api/server/v1/settings.js b/packages/rocketchat-api/server/v1/settings.js index b4bd19ebf505..e3fa0ee742e0 100644 --- a/packages/rocketchat-api/server/v1/settings.js +++ b/packages/rocketchat-api/server/v1/settings.js @@ -35,7 +35,7 @@ RocketChat.API.v1.addRoute('settings.oauth', { authRequired: false }, { const oAuthServicesEnabled = ServiceConfiguration.configurations.find({}, { fields: { secret: 0 } }).fetch(); return oAuthServicesEnabled.map((service) => { - if (service.custom || ['saml', 'cas'].includes(service.service)) { + if (service.custom || ['saml', 'cas', 'wordpress'].includes(service.service)) { return { ...service }; } diff --git a/packages/rocketchat-wordpress/common.js b/packages/rocketchat-wordpress/common.js index c1e2bd5fa3be..3bb2550e18bd 100644 --- a/packages/rocketchat-wordpress/common.js +++ b/packages/rocketchat-wordpress/common.js @@ -13,7 +13,7 @@ const config = { const WordPress = new CustomOAuth('wordpress', config); -const fillSettings = _.debounce(() => { +const fillSettings = _.debounce(Meteor.bindEnvironment(() => { config.serverURL = RocketChat.settings.get('API_Wordpress_URL'); delete config.identityPath; @@ -46,18 +46,34 @@ const fillSettings = _.debounce(() => { } break; case 'wordpress-com': - config.identityPath = '/rest/v1/me'; + config.identityPath = 'https://public-api.wordpress.com/rest/v1/me'; config.identityTokenSentVia = 'header'; - config.authorizePath = '/oauth2/authorize'; - config.tokenPath = '/oauth2/token'; + config.authorizePath = 'https://public-api.wordpress.com/oauth2/authorize'; + config.tokenPath = 'https://public-api.wordpress.com/oauth2/token'; config.scope = 'auth'; break; default: config.identityPath = '/oauth/me'; break; } - return WordPress.configure(config); -}, 1000); + + const result = WordPress.configure(config); + + const enabled = RocketChat.settings.get('Accounts_OAuth_Wordpress'); + if (enabled) { + ServiceConfiguration.configurations.upsert({ + service: 'wordpress' + }, { + $set: config + }); + } else { + ServiceConfiguration.configurations.remove({ + service: 'wordpress' + }); + } + + return result; +}), 1000); if (Meteor.isServer) { Meteor.startup(function() { diff --git a/packages/rocketchat-wordpress/startup.js b/packages/rocketchat-wordpress/startup.js index 39f520505ec7..80e204375668 100644 --- a/packages/rocketchat-wordpress/startup.js +++ b/packages/rocketchat-wordpress/startup.js @@ -39,7 +39,8 @@ RocketChat.settings.addGroup('OAuth', function() { key: 'custom', i18nLabel: 'Accounts_OAuth_Wordpress_server_type_custom' } - ] + ], + i18nLabel: 'Server_Type' }); const customOAuthQuery = [{