From 320499729f8e87a7a96cc25613712c3be6291764 Mon Sep 17 00:00:00 2001 From: Hudell Date: Thu, 14 Jun 2018 15:37:45 -0300 Subject: [PATCH 1/5] Add wordpress OAuth settings to api --- packages/rocketchat-api/server/v1/settings.js | 2 +- packages/rocketchat-wordpress/common.js | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) 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..0c40d5a2478c 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; @@ -56,8 +56,23 @@ const fillSettings = _.debounce(() => { config.identityPath = '/oauth/me'; break; } + + const enabled = RocketChat.settings.get('Accounts_OAuth_Wordpress'); + + if (enabled) { + ServiceConfiguration.configurations.upsert({ + service: 'wordpress' + }, { + $set: config + }); + } else { + ServiceConfiguration.configurations.remove({ + service: 'wordpress' + }); + } + return WordPress.configure(config); -}, 1000); +}), 2000); if (Meteor.isServer) { Meteor.startup(function() { From 802105514b013ee9678b8aec56a948b675f5c020 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 15 Jun 2018 15:21:47 -0300 Subject: [PATCH 2/5] Fixed wordpress oauth --- packages/rocketchat-wordpress/common.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-wordpress/common.js b/packages/rocketchat-wordpress/common.js index 0c40d5a2478c..7860e0c633ea 100644 --- a/packages/rocketchat-wordpress/common.js +++ b/packages/rocketchat-wordpress/common.js @@ -57,8 +57,9 @@ const fillSettings = _.debounce(Meteor.bindEnvironment(() => { break; } - const enabled = RocketChat.settings.get('Accounts_OAuth_Wordpress'); + const result = WordPress.configure(config); + const enabled = RocketChat.settings.get('Accounts_OAuth_Wordpress'); if (enabled) { ServiceConfiguration.configurations.upsert({ service: 'wordpress' @@ -71,7 +72,7 @@ const fillSettings = _.debounce(Meteor.bindEnvironment(() => { }); } - return WordPress.configure(config); + return result; }), 2000); if (Meteor.isServer) { From d1107b033412d629957b940c7dc54a94996b4ccf Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 15 Jun 2018 16:04:14 -0300 Subject: [PATCH 3/5] Changed debounce time back to 1 second --- packages/rocketchat-wordpress/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-wordpress/common.js b/packages/rocketchat-wordpress/common.js index 7860e0c633ea..c18f2f1927c1 100644 --- a/packages/rocketchat-wordpress/common.js +++ b/packages/rocketchat-wordpress/common.js @@ -73,7 +73,7 @@ const fillSettings = _.debounce(Meteor.bindEnvironment(() => { } return result; -}), 2000); +}), 1000); if (Meteor.isServer) { Meteor.startup(function() { From 5b8cd81398a8d0320e6f9306f7ce6f97fbc8893f Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 15 Jun 2018 16:21:30 -0300 Subject: [PATCH 4/5] Add URL for Wordpress.com --- packages/rocketchat-wordpress/common.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-wordpress/common.js b/packages/rocketchat-wordpress/common.js index c18f2f1927c1..3bb2550e18bd 100644 --- a/packages/rocketchat-wordpress/common.js +++ b/packages/rocketchat-wordpress/common.js @@ -46,10 +46,10 @@ const fillSettings = _.debounce(Meteor.bindEnvironment(() => { } 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: From b02c3090e6e08fcdbd19948372b0478eba48c797 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 15 Jun 2018 16:52:34 -0300 Subject: [PATCH 5/5] Add i18n label --- packages/rocketchat-wordpress/startup.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 = [{