diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 070067db2084096c2858842067b2e76bc65b81cb..0363f6a6bc286f128e57464c27fa760c2371f576 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -3,26 +3,30 @@ "Access_Online_Demo" : "Access the Online Demo", "Accounts_denyUnverifiedEmail" : "Deny unverified e-mail", "Accounts_EmailVerification" : "E-mail Verification", - "Accounts_Facebook": "Facebook Login", - "Accounts_Facebook_id": "Facebook App Id", - "Accounts_Facebook_secret": "Facebook Secret", - "Accounts_Github": "GitHub Login", - "Accounts_Github_id": "GitHub Id", - "Accounts_Github_secret": "GitHub Secret", - "Accounts_Google": "Google Login", - "Accounts_Google_id": "Google Id", - "Accounts_Google_secret": "Google Secret", - "Accounts_Linkedin": "LinkedIn Login", - "Accounts_Linkedin_id": "LinkedIn Id", - "Accounts_Linkedin_secret": "LinkedIn Secret", - "Accounts_ManuallyApproveNewUsers" : "Manually aprove new users", - "Accounts_Meteor": "Meteor Login", - "Accounts_Meteor_id": "Meteor Id", - "Accounts_Meteor_secret": "Meteor Secret", - "Accounts_RegistrationRequired" : "Registration Required", - "Accounts_Twitter": "Twitter Login", - "Accounts_Twitter_id": "Twitter Id", - "Accounts_Twitter_secret": "Twitter Secret", + "Accounts_OAuth_Facebook": "Facebook Login", + "Accounts_OAuth_Facebook_id": "Facebook App Id", + "Accounts_OAuth_Facebook_secret": "Facebook Secret", + "Accounts_OAuth_Github": "GitHub Login", + "Accounts_OAuth_Github_id": "GitHub Id", + "Accounts_OAuth_Github_secret": "GitHub Secret", + "Accounts_OAuth_Google": "Google Login", + "Accounts_OAuth_Google_id": "Google Id", + "Accounts_OAuth_Google_secret": "Google Secret", + "Accounts_OAuth_Linkedin": "LinkedIn Login", + "Accounts_OAuth_Linkedin_id": "LinkedIn Id", + "Accounts_OAuth_Linkedin_secret": "LinkedIn Secret", + "Accounts_OAuth_ManuallyApproveNewUsers" : "Manually aprove new users", + "Accounts_OAuth_Meteor": "Meteor Login", + "Accounts_OAuth_Meteor_id": "Meteor Id", + "Accounts_OAuth_Meteor_secret": "Meteor Secret", + "Accounts_OAuth_RegistrationRequired" : "Registration Required", + "Accounts_OAuth_Twitter": "Twitter Login", + "Accounts_OAuth_Twitter_id": "Twitter Id", + "Accounts_OAuth_Twitter_secret": "Twitter Secret", + "Accounts_OAuth_Custom_ID": "ID", + "Accounts_OAuth_Custom_URL": "URL", + "Accounts_OAuth_Custom_Secret": "Secret", + "Accounts_OAuth_Custom_Enable": "Enable", "Add_Members" : "Add Members", "Add_users" : "Add users", "Administration" : "Administration", diff --git a/packages/rocketchat-custom-oauth/custom_oauth_server.coffee b/packages/rocketchat-custom-oauth/custom_oauth_server.coffee index bd89cef669cb53a23cbe45524ba33adba89675e0..e2f8705f3e52a4d7ffb00f1b5cda34532420b3f3 100644 --- a/packages/rocketchat-custom-oauth/custom_oauth_server.coffee +++ b/packages/rocketchat-custom-oauth/custom_oauth_server.coffee @@ -10,7 +10,7 @@ class CustomOAuth return throw new Meteor.Error 'CustomOAuth: Options.serverURL is required and must be String' if not Match.test @options.tokenURL, String - return throw new Meteor.Error 'CustomOAuth: Options.tokenURL is required and must be String' + @options.tokenURL = '/oauth/token' @serverURL = options.serverURL @tokenURL = options.tokenURL diff --git a/packages/rocketchat-gitlab/common.coffee b/packages/rocketchat-gitlab/common.coffee index 804243f8aa9d122b7c2ceb979faace3d07ab1c33..d15549f4770c5f93247431ec5e7a6a98a3b1036c 100644 --- a/packages/rocketchat-gitlab/common.coffee +++ b/packages/rocketchat-gitlab/common.coffee @@ -1,6 +1,5 @@ Gitlab = new CustomOAuth 'gitlab', serverURL: 'https://gitlab.com' - tokenURL: '/oauth/token' addAutopublishFields: forLoggedInUser: ['services.gitlab'] forOtherUsers: ['services.gitlab.username'] diff --git a/packages/rocketchat-lib/package.js b/packages/rocketchat-lib/package.js index 2d0067656d1bd3b8bfc7b6167cead33b7f4da4b2..fc6d85e3824d63b1bbb3e14b3c2b0d831e10c582 100644 --- a/packages/rocketchat-lib/package.js +++ b/packages/rocketchat-lib/package.js @@ -50,7 +50,8 @@ Package.onUse(function(api) { 'settings/server/methods.coffee', 'settings/server/publication.coffee', 'settings/server/startup.coffee', - 'settings/server/updateServices.coffee' + 'settings/server/updateServices.coffee', + 'settings/server/addOAuthService.coffee' ], ['server']); api.addFiles('server/cdn.coffee', ['server']); diff --git a/packages/rocketchat-lib/settings/server/addOAuthService.coffee b/packages/rocketchat-lib/settings/server/addOAuthService.coffee new file mode 100644 index 0000000000000000000000000000000000000000..48d2c805ac32a01175457ffad276f6e2cbd5078d --- /dev/null +++ b/packages/rocketchat-lib/settings/server/addOAuthService.coffee @@ -0,0 +1,6 @@ +Meteor.methods + addOAuthService: (name) -> + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}" , false, { type: 'boolean', group: 'Accounts', section: name, i18nLabel: 'Accounts_Custom_Enable'} + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_url" , '' , { type: 'string' , group: 'Accounts', section: name, i18nLabel: 'Accounts_Custom_URL'} + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_id" , '' , { type: 'string' , group: 'Accounts', section: name, i18nLabel: 'Accounts_Custom_ID'} + RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_secret", '' , { type: 'string' , group: 'Accounts', section: name, i18nLabel: 'Accounts_Custom_Secret'} diff --git a/packages/rocketchat-lib/settings/server/startup.coffee b/packages/rocketchat-lib/settings/server/startup.coffee index 5cf50e35cca6185397819361f6414e3ffb0fae18..1cb75e2b1bce59be9a748aba04482c980e4fca41 100644 --- a/packages/rocketchat-lib/settings/server/startup.coffee +++ b/packages/rocketchat-lib/settings/server/startup.coffee @@ -9,27 +9,27 @@ Meteor.startup -> RocketChat.settings.add 'Accounts_AvatarResize', false, { type: 'boolean', group: 'Accounts', section: 'Avatar' } RocketChat.settings.add 'Accounts_AvatarSize', 200, { type: 'int', group: 'Accounts', section: 'Avatar' } - RocketChat.settings.add 'Accounts_Facebook', false, { type: 'boolean', group: 'Accounts', section: 'Facebook' } - RocketChat.settings.add 'Accounts_Facebook_id', '', { type: 'string', group: 'Accounts', section: 'Facebook' } - RocketChat.settings.add 'Accounts_Facebook_secret', '', { type: 'string', group: 'Accounts', section: 'Facebook' } - RocketChat.settings.add 'Accounts_Google', false, { type: 'boolean', group: 'Accounts', section: 'Google' } - RocketChat.settings.add 'Accounts_Google_id', '', { type: 'string', group: 'Accounts', section: 'Google' } - RocketChat.settings.add 'Accounts_Google_secret', '', { type: 'string', group: 'Accounts', section: 'Google' } - RocketChat.settings.add 'Accounts_Github', false, { type: 'boolean', group: 'Accounts', section: 'Github' } - RocketChat.settings.add 'Accounts_Github_id', '', { type: 'string', group: 'Accounts', section: 'Github' } - RocketChat.settings.add 'Accounts_Github_secret', '', { type: 'string', group: 'Accounts', section: 'Github' } - RocketChat.settings.add 'Accounts_Gitlab', false, { type: 'boolean', group: 'Accounts', section: 'Gitlab' } - RocketChat.settings.add 'Accounts_Gitlab_id', '', { type: 'string', group: 'Accounts', section: 'Gitlab' } - RocketChat.settings.add 'Accounts_Gitlab_secret', '', { type: 'string', group: 'Accounts', section: 'Gitlab' } - RocketChat.settings.add 'Accounts_Linkedin', false, { type: 'boolean', group: 'Accounts', section: 'Linkedin' } - RocketChat.settings.add 'Accounts_Linkedin_id', '', { type: 'string', group: 'Accounts', section: 'Linkedin' } - RocketChat.settings.add 'Accounts_Linkedin_secret', '', { type: 'string', group: 'Accounts', section: 'Linkedin' } - RocketChat.settings.add 'Accounts_Meteor', false, { type: 'boolean', group: 'Accounts', section: 'Meteor' } - RocketChat.settings.add 'Accounts_Meteor_id', '', { type: 'string', group: 'Accounts', section: 'Meteor' } - RocketChat.settings.add 'Accounts_Meteor_secret', '', { type: 'string', group: 'Accounts', section: 'Meteor' } - RocketChat.settings.add 'Accounts_Twitter', false, { type: 'boolean', group: 'Accounts', section: 'Twitter' } - RocketChat.settings.add 'Accounts_Twitter_id', '', { type: 'string', group: 'Accounts', section: 'Twitter' } - RocketChat.settings.add 'Accounts_Twitter_secret', '', { type: 'string', group: 'Accounts', section: 'Twitter' } + RocketChat.settings.add 'Accounts_OAuth_Facebook', false, { type: 'boolean', group: 'Accounts', section: 'Facebook' } + RocketChat.settings.add 'Accounts_OAuth_Facebook_id', '', { type: 'string', group: 'Accounts', section: 'Facebook' } + RocketChat.settings.add 'Accounts_OAuth_Facebook_secret', '', { type: 'string', group: 'Accounts', section: 'Facebook' } + RocketChat.settings.add 'Accounts_OAuth_Google', false, { type: 'boolean', group: 'Accounts', section: 'Google' } + RocketChat.settings.add 'Accounts_OAuth_Google_id', '', { type: 'string', group: 'Accounts', section: 'Google' } + RocketChat.settings.add 'Accounts_OAuth_Google_secret', '', { type: 'string', group: 'Accounts', section: 'Google' } + RocketChat.settings.add 'Accounts_OAuth_Github', false, { type: 'boolean', group: 'Accounts', section: 'Github' } + RocketChat.settings.add 'Accounts_OAuth_Github_id', '', { type: 'string', group: 'Accounts', section: 'Github' } + RocketChat.settings.add 'Accounts_OAuth_Github_secret', '', { type: 'string', group: 'Accounts', section: 'Github' } + RocketChat.settings.add 'Accounts_OAuth_Gitlab', false, { type: 'boolean', group: 'Accounts', section: 'Gitlab' } + RocketChat.settings.add 'Accounts_OAuth_Gitlab_id', '', { type: 'string', group: 'Accounts', section: 'Gitlab' } + RocketChat.settings.add 'Accounts_OAuth_Gitlab_secret', '', { type: 'string', group: 'Accounts', section: 'Gitlab' } + RocketChat.settings.add 'Accounts_OAuth_Linkedin', false, { type: 'boolean', group: 'Accounts', section: 'Linkedin' } + RocketChat.settings.add 'Accounts_OAuth_Linkedin_id', '', { type: 'string', group: 'Accounts', section: 'Linkedin' } + RocketChat.settings.add 'Accounts_OAuth_Linkedin_secret', '', { type: 'string', group: 'Accounts', section: 'Linkedin' } + RocketChat.settings.add 'Accounts_OAuth_Meteor', false, { type: 'boolean', group: 'Accounts', section: 'Meteor' } + RocketChat.settings.add 'Accounts_OAuth_Meteor_id', '', { type: 'string', group: 'Accounts', section: 'Meteor' } + RocketChat.settings.add 'Accounts_OAuth_Meteor_secret', '', { type: 'string', group: 'Accounts', section: 'Meteor' } + RocketChat.settings.add 'Accounts_OAuth_Twitter', false, { type: 'boolean', group: 'Accounts', section: 'Twitter' } + RocketChat.settings.add 'Accounts_OAuth_Twitter_id', '', { type: 'string', group: 'Accounts', section: 'Twitter' } + RocketChat.settings.add 'Accounts_OAuth_Twitter_secret', '', { type: 'string', group: 'Accounts', section: 'Twitter' } RocketChat.settings.addGroup 'General' RocketChat.settings.add 'Site_Name', 'Rocket.Chat', { type: 'string', group: 'General', public: true } diff --git a/packages/rocketchat-lib/settings/server/updateServices.coffee b/packages/rocketchat-lib/settings/server/updateServices.coffee index 1508deae1433861dbcf21d98230cd7c0eca64d7c..cbe64747fdab4c98e2762eae369d39227fdbddca 100644 --- a/packages/rocketchat-lib/settings/server/updateServices.coffee +++ b/packages/rocketchat-lib/settings/server/updateServices.coffee @@ -3,45 +3,48 @@ updateServices = -> Meteor.clearTimeout timer if timer? timer = Meteor.setTimeout -> - console.log 'Updating login services'.blue - services = - 'facebook': 'Facebook' - 'google': 'Google' - 'github': 'Github' - 'gitlab': 'Gitlab' - 'linkedin': 'Linkedin' - 'meteor-developer': 'Meteor' - 'twitter': 'Twitter' - - for serviceName, settingName of services - enable = Settings.findOne _id: "Accounts_#{settingName}", value: true - if enable? + services = Settings.find({_id: /^Accounts_OAuth_[a-z]+$/i}).fetch() + + for service in services + console.log "Updating login service #{service._id}".blue + + serviceName = service._id.replace('Accounts_', '') + + if serviceName is 'Meteor' + serviceName = 'meteor-developer' + + if service.value is true + if /Accounts_Custom/.test service._id + serviceName = service._id.replace('Accounts_Custom', '') + new CustomOAuth serviceName.toLowerCase(), + serverURL: Settings.findOne({_id: "#{service._id}_URL"})?.value + data = - clientId: Settings.findOne({_id: "Accounts_#{settingName}_id"})?.value - secret: Settings.findOne({_id: "Accounts_#{settingName}_secret"})?.value + clientId: Settings.findOne({_id: "#{service._id}_id"})?.value + secret: Settings.findOne({_id: "#{service._id}_secret"})?.value - if serviceName is 'facebook' + if serviceName is 'Facebook' data.appId = data.clientId delete data.clientId - if serviceName is 'twitter' + if serviceName is 'Twitter' data.consumerKey = data.clientId delete data.clientId - ServiceConfiguration.configurations.upsert {service: serviceName}, $set: data + ServiceConfiguration.configurations.upsert {service: serviceName.toLowerCase()}, $set: data else - ServiceConfiguration.configurations.remove {service: serviceName} + ServiceConfiguration.configurations.remove {service: serviceName.toLowerCase()} , 2000 Settings.find().observe added: (record) -> - if /^Accounts_.+/.test record._id + if /^Accounts_OAuth_.+/.test record._id updateServices() changed: (record) -> - if /^Accounts_.+/.test record._id + if /^Accounts_OAuth_.+/.test record._id updateServices() removed: (record) -> - if /^Accounts_.+/.test record._id + if /^Accounts_OAuth_.+/.test record._id updateServices() diff --git a/server/startup/migrations/v18.coffee b/server/startup/migrations/v18.coffee new file mode 100644 index 0000000000000000000000000000000000000000..aca465a0108b0e23a8267c6cfb4c2a81fb541553 --- /dev/null +++ b/server/startup/migrations/v18.coffee @@ -0,0 +1,33 @@ +Meteor.startup -> + Migrations.add + version: 18 + up: -> + changes = + Accounts_Facebook: 'Accounts_OAuth_Facebook' + Accounts_Facebook_id: 'Accounts_OAuth_Facebook_id' + Accounts_Facebook_secret: 'Accounts_OAuth_Facebook_secret' + Accounts_Google: 'Accounts_OAuth_Google' + Accounts_Google_id: 'Accounts_OAuth_Google_id' + Accounts_Google_secret: 'Accounts_OAuth_Google_secret' + Accounts_Github: 'Accounts_OAuth_Github' + Accounts_Github_id: 'Accounts_OAuth_Github_id' + Accounts_Github_secret: 'Accounts_OAuth_Github_secret' + Accounts_Gitlab: 'Accounts_OAuth_Gitlab' + Accounts_Gitlab_id: 'Accounts_OAuth_Gitlab_id' + Accounts_Gitlab_secret: 'Accounts_OAuth_Gitlab_secret' + Accounts_Linkedin: 'Accounts_OAuth_Linkedin' + Accounts_Linkedin_id: 'Accounts_OAuth_Linkedin_id' + Accounts_Linkedin_secret: 'Accounts_OAuth_Linkedin_secret' + Accounts_Meteor: 'Accounts_OAuth_Meteor' + Accounts_Meteor_id: 'Accounts_OAuth_Meteor_id' + Accounts_Meteor_secret: 'Accounts_OAuth_Meteor_secret' + Accounts_Twitter: 'Accounts_OAuth_Twitter' + Accounts_Twitter_id: 'Accounts_OAuth_Twitter_id' + Accounts_Twitter_secret: 'Accounts_OAuth_Twitter_secret' + + for from, to of changes + record = Settings.findOne _id: from + if record? + delete record._id + Settings.upsert {_id: to}, record + Settings.remove _id: from \ No newline at end of file