From b1e7191a178aa390e5c2c4e7593d1691a24cf5aa Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 5 Jul 2019 17:47:10 -0300 Subject: [PATCH 1/7] Change OAuth Apps to accept multiple redirect URIs --- .../client/admin/views/oauthApp.html | 2 +- .../server/admin/functions/parseUriList.js | 21 +++++++++++++++++++ .../server/admin/methods/addOAuthApp.js | 9 ++++++++ .../server/admin/methods/updateOAuthApp.js | 11 +++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 app/oauth2-server-config/server/admin/functions/parseUriList.js diff --git a/app/oauth2-server-config/client/admin/views/oauthApp.html b/app/oauth2-server-config/client/admin/views/oauthApp.html index 1696d4c3dd4e..5bcab86d702b 100644 --- a/app/oauth2-server-config/client/admin/views/oauthApp.html +++ b/app/oauth2-server-config/client/admin/views/oauthApp.html @@ -22,7 +22,7 @@
- +
{{_ "After_OAuth2_authentication_users_will_be_redirected_to_this_URL"}}
diff --git a/app/oauth2-server-config/server/admin/functions/parseUriList.js b/app/oauth2-server-config/server/admin/functions/parseUriList.js new file mode 100644 index 000000000000..37e1cab65bc2 --- /dev/null +++ b/app/oauth2-server-config/server/admin/functions/parseUriList.js @@ -0,0 +1,21 @@ +export const parseUriList = (userUri) => { + if (userUri.indexOf('\n') < 0 && userUri.indexOf(',') < 0) { + return userUri; + } + + const uriList = []; + userUri.split(/[,\n]/).forEach((item) => { + const uri = item.trim(); + if (uri === '') { + return; + } + + uriList.push(uri); + }); + + if (uriList.length === 1) { + return uriList.pop(); + } + + return uriList; +}; diff --git a/app/oauth2-server-config/server/admin/methods/addOAuthApp.js b/app/oauth2-server-config/server/admin/methods/addOAuthApp.js index a5ef900f34bd..abe946004d49 100644 --- a/app/oauth2-server-config/server/admin/methods/addOAuthApp.js +++ b/app/oauth2-server-config/server/admin/methods/addOAuthApp.js @@ -5,6 +5,8 @@ import _ from 'underscore'; import { hasPermission } from '../../../../authorization'; import { Users, OAuthApps } from '../../../../models'; +import { parseUriList } from '../functions/parseUriList'; + Meteor.methods({ addOAuthApp(application) { if (!hasPermission(this.userId, 'manage-oauth-apps')) { @@ -19,6 +21,13 @@ Meteor.methods({ if (!_.isBoolean(application.active)) { throw new Meteor.Error('error-invalid-arguments', 'Invalid arguments', { method: 'addOAuthApp' }); } + + application.redirectUri = parseUriList(application.redirectUri); + + if (Array.isArray(application.redirectUri) && application.redirectUri.length === 0) { + throw new Meteor.Error('error-invalid-redirectUri', 'Invalid redirectUri', { method: 'addOAuthApp' }); + } + application.clientId = Random.id(); application.clientSecret = Random.secret(); application._createdAt = new Date(); diff --git a/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js b/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js index 6043a34a23f0..997aa4fbd9b0 100644 --- a/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js +++ b/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js @@ -4,6 +4,8 @@ import _ from 'underscore'; import { hasPermission } from '../../../../authorization'; import { OAuthApps, Users } from '../../../../models'; +import { parseUriList } from '../functions/parseUriList'; + Meteor.methods({ updateOAuthApp(applicationId, application) { if (!hasPermission(this.userId, 'manage-oauth-apps')) { @@ -22,11 +24,18 @@ Meteor.methods({ if (currentApplication == null) { throw new Meteor.Error('error-application-not-found', 'Application not found', { method: 'updateOAuthApp' }); } + + const redirectUri = parseUriList(application.redirectUri); + + if (Array.isArray(redirectUri) && redirectUri.length === 0) { + throw new Meteor.Error('error-invalid-redirectUri', 'Invalid redirectUri', { method: 'updateOAuthApp' }); + } + OAuthApps.update(applicationId, { $set: { name: application.name, active: application.active, - redirectUri: application.redirectUri, + redirectUri, _updatedAt: new Date(), _updatedBy: Users.findOne(this.userId, { fields: { From 4ede63f59a160d4a28e90937960b670bbd5de215 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 5 Jul 2019 18:02:57 -0300 Subject: [PATCH 2/7] Removed empty lines (eslint fixes) --- app/oauth2-server-config/server/admin/methods/addOAuthApp.js | 1 - app/oauth2-server-config/server/admin/methods/updateOAuthApp.js | 1 - 2 files changed, 2 deletions(-) diff --git a/app/oauth2-server-config/server/admin/methods/addOAuthApp.js b/app/oauth2-server-config/server/admin/methods/addOAuthApp.js index abe946004d49..58b8025d4a53 100644 --- a/app/oauth2-server-config/server/admin/methods/addOAuthApp.js +++ b/app/oauth2-server-config/server/admin/methods/addOAuthApp.js @@ -4,7 +4,6 @@ import _ from 'underscore'; import { hasPermission } from '../../../../authorization'; import { Users, OAuthApps } from '../../../../models'; - import { parseUriList } from '../functions/parseUriList'; Meteor.methods({ diff --git a/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js b/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js index 997aa4fbd9b0..213205ec30e4 100644 --- a/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js +++ b/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js @@ -3,7 +3,6 @@ import _ from 'underscore'; import { hasPermission } from '../../../../authorization'; import { OAuthApps, Users } from '../../../../models'; - import { parseUriList } from '../functions/parseUriList'; Meteor.methods({ From 10e9539054b0ed8c3a354718ff75039648604dc2 Mon Sep 17 00:00:00 2001 From: Pierre Lehnen Date: Mon, 15 Jul 2019 11:18:31 -0300 Subject: [PATCH 3/7] Updated OAuth server package version --- .meteor/versions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.meteor/versions b/.meteor/versions index e1e6cb375828..cbb673b88769 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -129,7 +129,7 @@ rocketchat:i18n@0.0.1 rocketchat:livechat@0.0.1 rocketchat:mongo-config@0.0.1 rocketchat:monitoring@2.30.2_3 -rocketchat:oauth2-server@2.0.0 +rocketchat:oauth2-server@2.1.0 rocketchat:push@3.3.1 rocketchat:streamer@1.0.2 rocketchat:version@1.0.0 From d290726c162bac6a7ec92444ece75762d69900af Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 16 Jul 2019 16:23:58 -0300 Subject: [PATCH 4/7] Changed OAuth apps to always use an array for the redirect URIs --- .../server/admin/functions/parseUriList.js | 4 ---- app/oauth2-server-config/server/admin/methods/addOAuthApp.js | 2 +- .../server/admin/methods/updateOAuthApp.js | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/oauth2-server-config/server/admin/functions/parseUriList.js b/app/oauth2-server-config/server/admin/functions/parseUriList.js index 37e1cab65bc2..f00fa792f80a 100644 --- a/app/oauth2-server-config/server/admin/functions/parseUriList.js +++ b/app/oauth2-server-config/server/admin/functions/parseUriList.js @@ -13,9 +13,5 @@ export const parseUriList = (userUri) => { uriList.push(uri); }); - if (uriList.length === 1) { - return uriList.pop(); - } - return uriList; }; diff --git a/app/oauth2-server-config/server/admin/methods/addOAuthApp.js b/app/oauth2-server-config/server/admin/methods/addOAuthApp.js index 58b8025d4a53..cb4d73e19f27 100644 --- a/app/oauth2-server-config/server/admin/methods/addOAuthApp.js +++ b/app/oauth2-server-config/server/admin/methods/addOAuthApp.js @@ -23,7 +23,7 @@ Meteor.methods({ application.redirectUri = parseUriList(application.redirectUri); - if (Array.isArray(application.redirectUri) && application.redirectUri.length === 0) { + if (application.redirectUri.length === 0) { throw new Meteor.Error('error-invalid-redirectUri', 'Invalid redirectUri', { method: 'addOAuthApp' }); } diff --git a/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js b/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js index 213205ec30e4..007f5be2e95c 100644 --- a/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js +++ b/app/oauth2-server-config/server/admin/methods/updateOAuthApp.js @@ -26,7 +26,7 @@ Meteor.methods({ const redirectUri = parseUriList(application.redirectUri); - if (Array.isArray(redirectUri) && redirectUri.length === 0) { + if (redirectUri.length === 0) { throw new Meteor.Error('error-invalid-redirectUri', 'Invalid redirectUri', { method: 'updateOAuthApp' }); } From 321106da2f5e70275837fa10c236fb4a955dec01 Mon Sep 17 00:00:00 2001 From: Pierre Lehnen Date: Sat, 20 Jul 2019 13:37:11 -0300 Subject: [PATCH 5/7] Add description explaining that you can add multiple redirect URLs --- packages/rocketchat-i18n/i18n/en.i18n.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index b5955587779b..23b207c32a8d 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -232,7 +232,7 @@ "Administration": "Administration", "Adult_images_are_not_allowed": "Adult images are not allowed", "Advocacy": "Advocacy", - "After_OAuth2_authentication_users_will_be_redirected_to_this_URL": "After OAuth2 authentication, users will be redirected to this URL", + "After_OAuth2_authentication_users_will_be_redirected_to_this_URL": "After OAuth2 authentication, users will be redirected to an URL on this list.
You can add one URL per line.", "Agent": "Agent", "Agent_added": "Agent added", "Agent_removed": "Agent removed", From 0bbc948885ccdee526c8be2ea599a1eef3978433 Mon Sep 17 00:00:00 2001 From: Pierre Lehnen Date: Sat, 20 Jul 2019 13:42:05 -0300 Subject: [PATCH 6/7] Removed HTML tag --- packages/rocketchat-i18n/i18n/en.i18n.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 70b46478b6e6..90fa82d00229 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -232,7 +232,7 @@ "Administration": "Administration", "Adult_images_are_not_allowed": "Adult images are not allowed", "Advocacy": "Advocacy", - "After_OAuth2_authentication_users_will_be_redirected_to_this_URL": "After OAuth2 authentication, users will be redirected to an URL on this list.
You can add one URL per line.", + "After_OAuth2_authentication_users_will_be_redirected_to_this_URL": "After OAuth2 authentication, users will be redirected to an URL on this list. You can add one URL per line.", "Agent": "Agent", "Agent_added": "Agent added", "Agent_removed": "Agent removed", From 86e4ffa4780a9cdf1c275d579db054df86a25bd5 Mon Sep 17 00:00:00 2001 From: Pierre Lehnen Date: Sat, 20 Jul 2019 13:50:03 -0300 Subject: [PATCH 7/7] Show urls split by new line --- app/oauth2-server-config/client/admin/views/oauthApp.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/oauth2-server-config/client/admin/views/oauthApp.js b/app/oauth2-server-config/client/admin/views/oauthApp.js index 1ef9f76d3287..e0f4cc0f71c6 100644 --- a/app/oauth2-server-config/client/admin/views/oauthApp.js +++ b/app/oauth2-server-config/client/admin/views/oauthApp.js @@ -31,6 +31,10 @@ Template.oauthApp.helpers({ if (data) { data.authorization_url = Meteor.absoluteUrl('oauth/authorize'); data.access_token_url = Meteor.absoluteUrl('oauth/token'); + if (Array.isArray(data.redirectUri)) { + data.redirectUri = data.redirectUri.join('\n'); + } + Template.instance().record.set(data); return data; }