diff --git a/packages/rocketchat-api/server/v1/misc.js b/packages/rocketchat-api/server/v1/misc.js index 05fee75aec6b..b15c2d1e456d 100644 --- a/packages/rocketchat-api/server/v1/misc.js +++ b/packages/rocketchat-api/server/v1/misc.js @@ -18,29 +18,6 @@ RocketChat.API.v1.addRoute('info', { authRequired: false }, { } }); -RocketChat.API.v1.addRoute('settings.oauth', { authRequired: false }, { - get() { - const mountOAuthServices = () => { - const oAuthServicesEnabled = ServiceConfiguration.configurations.find({}).fetch(); - - return oAuthServicesEnabled.map((service) => { - return { - id: service._id, - name: service.service, - appId: service.appId || service.clientId, - buttonLabelText: service.buttonLabelText || '', - buttonColor: service.buttonColor || '', - buttonLabelColor: service.buttonLabelColor || '' - }; - }); - }; - - return RocketChat.API.v1.success({ - services: mountOAuthServices() - }); - } -}); - RocketChat.API.v1.addRoute('me', { authRequired: true }, { get() { const me = _.pick(this.user, [ diff --git a/packages/rocketchat-api/server/v1/settings.js b/packages/rocketchat-api/server/v1/settings.js index 3662ba148530..fc333c1994ac 100644 --- a/packages/rocketchat-api/server/v1/settings.js +++ b/packages/rocketchat-api/server/v1/settings.js @@ -29,6 +29,33 @@ RocketChat.API.v1.addRoute('settings.public', { authRequired: false }, { } }); +RocketChat.API.v1.addRoute('settings.oauth', { authRequired: false }, { + get() { + const mountOAuthServices = () => { + const oAuthServicesEnabled = ServiceConfiguration.configurations.find({}).fetch(); + + return oAuthServicesEnabled.map((service) => { + if (service.custom) { + return { ...service }; + } + return { + id: service._id, + name: service.service, + clientId: service.appId || service.clientId, + buttonLabelText: service.buttonLabelText || '', + buttonColor: service.buttonColor || '', + buttonLabelColor: service.buttonLabelColor || '', + custom: false + }; + }); + }; + + return RocketChat.API.v1.success({ + services: mountOAuthServices() + }); + } +}); + RocketChat.API.v1.addRoute('settings', { authRequired: true }, { get() { const { offset, count } = this.getPaginationItems(); @@ -90,7 +117,7 @@ RocketChat.API.v1.addRoute('service.configurations', { authRequired: false }, { const ServiceConfiguration = Package['service-configuration'].ServiceConfiguration; return RocketChat.API.v1.success({ - configurations: ServiceConfiguration.configurations.find({}, {fields: {secret: 0}}).fetch() + configurations: ServiceConfiguration.configurations.find({}, { fields: { secret: 0 } }).fetch() }); } }); diff --git a/tests/end-to-end/api/00-miscellaneous.js b/tests/end-to-end/api/00-miscellaneous.js index d655110d4c74..a84da2e293f6 100644 --- a/tests/end-to-end/api/00-miscellaneous.js +++ b/tests/end-to-end/api/00-miscellaneous.js @@ -73,29 +73,5 @@ describe('miscellaneous', function() { .end(done); }); - describe('/settings.oauth', () => { - it('should have return list of available oauth services when user is not logged', (done) => { - request.get(api('settings.oauth')) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('services').and.to.be.an('array'); - }) - .end(done); - }); - - it('should have return list of available oauth services when user is logged', (done) => { - request.get(api('settings.oauth')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('services').and.to.be.an('array'); - }) - .end(done); - }); - }); }); diff --git a/tests/end-to-end/api/08-settings.js b/tests/end-to-end/api/08-settings.js index fa6cd5b0a65b..d1c0fd0a0303 100644 --- a/tests/end-to-end/api/08-settings.js +++ b/tests/end-to-end/api/08-settings.js @@ -65,4 +65,29 @@ describe('[Settings]', function() { .end(done); }); }); + + describe('/settings.oauth', () => { + it('should have return list of available oauth services when user is not logged', (done) => { + request.get(api('settings.oauth')) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('services').and.to.be.an('array'); + }) + .end(done); + }); + + it('should have return list of available oauth services when user is logged', (done) => { + request.get(api('settings.oauth')) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('services').and.to.be.an('array'); + }) + .end(done); + }); + }); });