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

Configure custom oAuth on client and other improvements

parent e56c048a
No related branches found
No related tags found
No related merge requests found
Meteor.startup ->
ServiceConfiguration.configurations.find({custom: true}).observe
added: (record) ->
new CustomOAuth record.service,
serverURL: record.serverURL
Template.loginServices.helpers
loginService: ->
services = []
......
Services = {}
class CustomOAuth
constructor: (@name, @options) ->
constructor: (@name, options) ->
if not Match.test @name, String
return throw new Meteor.Error 'CustomOAuth: Name is required and must be String'
if not Match.test @options, Object
if Services[@name]?
Services[@name].configure options
return
Services[@name] = @
@configure options
@userAgent = "Meteor"
if Meteor.release
@userAgent += '/' + Meteor.release
Accounts.oauth.registerService @name
@registerService()
configure: (options) ->
if not Match.test options, Object
return throw new Meteor.Error 'CustomOAuth: Options is required and must be Object'
if not Match.test @options.serverURL, String
if not Match.test options.serverURL, String
return throw new Meteor.Error 'CustomOAuth: Options.serverURL is required and must be String'
if not Match.test @options.tokenURL, String
@options.tokenURL = '/oauth/token'
if not Match.test options.tokenURL, String
options.tokenURL = '/oauth/token'
@serverURL = options.serverURL
@tokenURL = options.tokenURL
if not Match.test @options.addAutopublishFields, Object
if Match.test options.addAutopublishFields, Object
Accounts.addAutopublishFields options.addAutopublishFields
Accounts.oauth.registerService @name
@userAgent = "Meteor"
if Meteor.release
@userAgent += '/' + Meteor.release
@registerService()
getAccessToken: (query) ->
config = ServiceConfiguration.configurations.findOne service: @name
if not config?
......
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'}
RocketChat.settings.add "Accounts_OAuth_Custom_#{name}" , false, { type: 'boolean', group: 'Accounts', section: name, i18nLabel: 'Accounts_OAuth_Custom_Enable'}
RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_url" , '' , { type: 'string' , group: 'Accounts', section: name, i18nLabel: 'Accounts_OAuth_Custom_URL'}
RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_id" , '' , { type: 'string' , group: 'Accounts', section: name, i18nLabel: 'Accounts_OAuth_Custom_ID'}
RocketChat.settings.add "Accounts_OAuth_Custom_#{name}_secret", '' , { type: 'string' , group: 'Accounts', section: name, i18nLabel: 'Accounts_OAuth_Custom_Secret'}
......@@ -3,26 +3,28 @@ updateServices = ->
Meteor.clearTimeout timer if timer?
timer = Meteor.setTimeout ->
services = Settings.find({_id: /^Accounts_OAuth_[a-z]+$/i}).fetch()
services = Settings.find({_id: /^(Accounts_OAuth_|Accounts_OAuth_Custom_)[a-z]+$/i}).fetch()
for service in services
console.log "Updating login service #{service._id}".blue
serviceName = service._id.replace('Accounts_', '')
serviceName = service._id.replace('Accounts_OAuth_', '')
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: "#{service._id}_id"})?.value
secret: Settings.findOne({_id: "#{service._id}_secret"})?.value
if /Accounts_OAuth_Custom_/.test service._id
serviceName = service._id.replace('Accounts_OAuth_Custom_', '')
data.custom = true
data.serverURL = Settings.findOne({_id: "#{service._id}_url"})?.value
new CustomOAuth serviceName.toLowerCase(),
serverURL: data.serverURL
if serviceName is 'Facebook'
data.appId = data.clientId
delete data.clientId
......
......@@ -30,4 +30,6 @@ Meteor.startup ->
if record?
delete record._id
Settings.upsert {_id: to}, record
Settings.remove _id: from
\ No newline at end of file
Settings.remove _id: from
ServiceConfiguration.configurations.remove({})
\ 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