Skip to content
Snippets Groups Projects
Commit e56c048a authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Change OAuth settings names and auto configure custom OAuths

parent 5dd49692
No related branches found
No related tags found
No related merge requests found
......@@ -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",
......
......@@ -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
......
Gitlab = new CustomOAuth 'gitlab',
serverURL: 'https://gitlab.com'
tokenURL: '/oauth/token'
addAutopublishFields:
forLoggedInUser: ['services.gitlab']
forOtherUsers: ['services.gitlab.username']
......
......@@ -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']);
......
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'}
......@@ -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 }
......
......@@ -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()
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment