diff --git a/packages/rocketchat-api/server/v1/misc.js b/packages/rocketchat-api/server/v1/misc.js index c1bf99ef3e997..4fad6919a4304 100644 --- a/packages/rocketchat-api/server/v1/misc.js +++ b/packages/rocketchat-api/server/v1/misc.js @@ -18,6 +18,29 @@ 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/tests/end-to-end/api/00-miscellaneous.js b/tests/end-to-end/api/00-miscellaneous.js index 76ac7fa787aaf..20d68fac21009 100644 --- a/tests/end-to-end/api/00-miscellaneous.js +++ b/tests/end-to-end/api/00-miscellaneous.js @@ -70,4 +70,30 @@ 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); + }); + }); + });