From 882a86f9445fdf3c031cd71c611b435377374086 Mon Sep 17 00:00:00 2001 From: Steve Adams Date: Sun, 4 Nov 2018 22:24:42 +1100 Subject: [PATCH 1/8] add custom domain support --- src/management/CustomDomainsManager.js | 167 +++++++++++++++++++++++++ src/management/index.js | 115 +++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 src/management/CustomDomainsManager.js diff --git a/src/management/CustomDomainsManager.js b/src/management/CustomDomainsManager.js new file mode 100644 index 000000000..fd8d0adcd --- /dev/null +++ b/src/management/CustomDomainsManager.js @@ -0,0 +1,167 @@ +var ArgumentError = require('rest-facade').ArgumentError; +var utils = require('../utils'); +var Auth0RestClient = require('../Auth0RestClient'); +var RetryRestClient = require('../RetryRestClient'); + +/** + * @class CustomDomainsManager + * Auth0 Custom Domains Manager. + * + * {@link https://auth0.com/docs/api/management/v2#!/Custom_Domains/get_custom_domains CustomDomains} represent + * custom domain names. + * You can learn more about this in the + * {@link https://auth0.com/docs/custom-domains CustomDomains} section of the + * documentation. + * @constructor + * @memberOf module:management + * + * @param {Object} options The client options. + * @param {String} options.baseUrl The URL of the API. + * @param {Object} [options.headers] Headers to be included in all requests. + * @param {Object} [options.retry] Retry Policy Config + */ +var CustomDomainsManager = function(options) { + if (options === null || typeof options !== 'object') { + throw new ArgumentError('Must provide client options'); + } + + if (options.baseUrl === null || options.baseUrl === undefined) { + throw new ArgumentError('Must provide a base URL for the API'); + } + + if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { + throw new ArgumentError('The provided base URL is invalid'); + } + + /** + * Options object for the Rest Client instance. + * + * @type {Object} + */ + var clientOptions = { + errorFormatter: { message: 'message', name: 'error' }, + headers: options.headers, + query: { repeatParams: false } + }; + + /** + * Provides an abstraction layer for consuming the + * {@link https://auth0.com/docs/api/v2#!/Clients Auth0 Clients endpoint}. + * + * @type {external:RestClient} + */ + var auth0RestClient = new Auth0RestClient( + options.baseUrl + '/custom-domains/:id', + clientOptions, + options.tokenProvider + ); + this.resource = new RetryRestClient(auth0RestClient, options.retry); +}; + +/** + * Create an Auth0 Custom Domain. + * + * @method create + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.create(data, function (err) { + * if (err) { + * // Handle error. + * } + * + * // CustomDomain created. + * }); + * + * @param {Object} data The custom domain data object. + * @param {Function} [cb] Callback function. + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'create', 'resource.create'); + +/** + * Get all Auth0 CustomDomains. + * + * @method getAll + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.getAll(function (err, customDomains) { + * console.log(customDomains.length); + * }); + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'getAll', 'resource.getAll'); + +/** + * Get a Custom Domain. + * + * @method get + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.get({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { + * if (err) { + * // Handle error. + * } + * + * console.log(customDomain); + * }); + * + * @param {Object} params Custom Domain parameters. + * @param {String} params.id Custom Domain ID. + * @param {Function} [cb] Callback function. + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'get', 'resource.get'); + +/** + * Verify a Custom Domain. + * + * @method verify + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.verify({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { + * if (err) { + * // Handle error. + * } + * + * console.log(customDomain); + * }); + * + * @param {Object} params Custom Domain parameters. + * @param {String} params.id Custom Domain ID. + * @param {Function} [cb] Callback function. + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'verify', 'resource.get'); + +/** + * Delete a Custom Domain. + * + * @method delete + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.delete({ id: CUSTOM_DOMAIN_ID }, function (err) { + * if (err) { + * // Handle error. + * } + * + * // CustomDomain deleted. + * }); + * + * @param {Object} params Custom Domain parameters. + * @param {String} params.id Custom Domain ID. + * @param {Function} [cb] Callback function. + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'delete', 'resource.delete'); + +module.exports = CustomDomainsManager; diff --git a/src/management/index.js b/src/management/index.js index ba35e4734..7d38ebd8c 100644 --- a/src/management/index.js +++ b/src/management/index.js @@ -27,6 +27,7 @@ var ManagementTokenProvider = require('./ManagementTokenProvider'); var RulesConfigsManager = require('./RulesConfigsManager'); var EmailTemplatesManager = require('./EmailTemplatesManager'); var GuardianManager = require('./GuardianManager'); +var CustomDomainsManager = require('./CustomDomainsManager'); var BASE_URL_FORMAT = 'https://%s/api/v2'; var MANAGEMENT_API_AUD_FORMAT = 'https://%s/api/v2/'; @@ -164,6 +165,14 @@ var ManagementClient = function(options) { */ this.guardian = new GuardianManager(managerOptions); + /** + * Simple abstraction for performing CRUD operations on the + * custom domains endpoint. + * + * @type {CustomDomainsManager} + */ + this.customDomains = new CustomDomainsManager(managerOptions); + /** * Simple abstraction for performing CRUD operations on the * connections endpoint. @@ -1929,4 +1938,110 @@ utils.wrapPropertyMethod(ManagementClient, 'getRulesConfigs', 'rulesConfigs.getA */ utils.wrapPropertyMethod(ManagementClient, 'deleteRulesConfig', 'rulesConfigs.delete'); +/** + * Create an Auth0 Custom Domain. + * + * @method create + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.create(data, function (err) { + * if (err) { + * // Handle error. + * } + * + * // CustomDomain created. + * }); + * + * @param {Object} data The custom domain data object. + * @param {Function} [cb] Callback function. + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'createCustomDomain', 'customDomains.create'); + +/** + * Get all Auth0 CustomDomains. + * + * @method getAll + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.getAll(function (err, customDomains) { + * console.log(customDomains.length); + * }); + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'getCustomDomains', 'customDomains.getAll'); + +/** + * Get a Custom Domain. + * + * @method get + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.get({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { + * if (err) { + * // Handle error. + * } + * + * console.log(customDomain); + * }); + * + * @param {Object} params Custom Domain parameters. + * @param {String} params.id Custom Domain ID. + * @param {Function} [cb] Callback function. + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'getCustomDomain', 'customDomains.get'); + +/** + * Verify a Custom Domain. + * + * @method verify + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.verify({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { + * if (err) { + * // Handle error. + * } + * + * console.log(customDomain); + * }); + * + * @param {Object} params Custom Domain parameters. + * @param {String} params.id Custom Domain ID. + * @param {Function} [cb] Callback function. + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'verifyCustomDomain', 'customDomains.verify'); + +/** + * Delete a Custom Domain. + * + * @method delete + * @memberOf module:management.CustomDomainsManager.prototype + * + * @example + * management.customDomains.delete({ id: CUSTOM_DOMAIN_ID }, function (err) { + * if (err) { + * // Handle error. + * } + * + * // CustomDomain deleted. + * }); + * + * @param {Object} params Custom Domain parameters. + * @param {String} params.id Custom Domain ID. + * @param {Function} [cb] Callback function. + * + * @return {Promise|undefined} + */ +utils.wrapPropertyMethod(CustomDomainsManager, 'delete', 'customDomains.delete'); + module.exports = ManagementClient; From edde5c9ff82216c5236b76c8df803c048a83bb9e Mon Sep 17 00:00:00 2001 From: Steve Adams Date: Sun, 4 Nov 2018 22:32:10 +1100 Subject: [PATCH 2/8] fix customDomains --- src/management/index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/management/index.js b/src/management/index.js index 7d38ebd8c..867516504 100644 --- a/src/management/index.js +++ b/src/management/index.js @@ -1945,7 +1945,7 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteRulesConfig', 'rulesConfigs.de * @memberOf module:management.CustomDomainsManager.prototype * * @example - * management.customDomains.create(data, function (err) { + * management.customDomains.createCustomDomain(data, function (err) { * if (err) { * // Handle error. * } @@ -1958,7 +1958,7 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteRulesConfig', 'rulesConfigs.de * * @return {Promise|undefined} */ -utils.wrapPropertyMethod(CustomDomainsManager, 'createCustomDomain', 'customDomains.create'); +utils.wrapPropertyMethod(ManagementClient, 'createCustomDomain', 'customDomains.create'); /** * Get all Auth0 CustomDomains. @@ -1967,13 +1967,13 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'createCustomDomain', 'customDoma * @memberOf module:management.CustomDomainsManager.prototype * * @example - * management.customDomains.getAll(function (err, customDomains) { + * management.customDomains.getCustomDomains(function (err, customDomains) { * console.log(customDomains.length); * }); * * @return {Promise|undefined} */ -utils.wrapPropertyMethod(CustomDomainsManager, 'getCustomDomains', 'customDomains.getAll'); +utils.wrapPropertyMethod(ManagementClient, 'getCustomDomains', 'customDomains.getAll'); /** * Get a Custom Domain. @@ -1982,7 +1982,7 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'getCustomDomains', 'customDomain * @memberOf module:management.CustomDomainsManager.prototype * * @example - * management.customDomains.get({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { + * management.customDomains.getCustomDomain({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { * if (err) { * // Handle error. * } @@ -1996,7 +1996,7 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'getCustomDomains', 'customDomain * * @return {Promise|undefined} */ -utils.wrapPropertyMethod(CustomDomainsManager, 'getCustomDomain', 'customDomains.get'); +utils.wrapPropertyMethod(ManagementClient, 'getCustomDomain', 'customDomains.get'); /** * Verify a Custom Domain. @@ -2005,7 +2005,7 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'getCustomDomain', 'customDomains * @memberOf module:management.CustomDomainsManager.prototype * * @example - * management.customDomains.verify({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { + * management.customDomains.verifyCustomDomain({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { * if (err) { * // Handle error. * } @@ -2019,7 +2019,7 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'getCustomDomain', 'customDomains * * @return {Promise|undefined} */ -utils.wrapPropertyMethod(CustomDomainsManager, 'verifyCustomDomain', 'customDomains.verify'); +utils.wrapPropertyMethod(ManagementClient, 'verifyCustomDomain', 'customDomains.verify'); /** * Delete a Custom Domain. @@ -2028,7 +2028,7 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'verifyCustomDomain', 'customDoma * @memberOf module:management.CustomDomainsManager.prototype * * @example - * management.customDomains.delete({ id: CUSTOM_DOMAIN_ID }, function (err) { + * management.deleteCustomDomain({ id: CUSTOM_DOMAIN_ID }, function (err) { * if (err) { * // Handle error. * } @@ -2042,6 +2042,6 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'verifyCustomDomain', 'customDoma * * @return {Promise|undefined} */ -utils.wrapPropertyMethod(CustomDomainsManager, 'delete', 'customDomains.delete'); +utils.wrapPropertyMethod(ManagementClient, 'deleteCustomDomain', 'customDomains.delete'); module.exports = ManagementClient; From 8427b66ed6cc719e825378abc25a60bcb0633985 Mon Sep 17 00:00:00 2001 From: Steve Adams Date: Mon, 5 Nov 2018 14:15:05 +1100 Subject: [PATCH 3/8] add custom domains test --- test/management/custom-domains.tests.js | 398 ++++++++++++++++++++++++ 1 file changed, 398 insertions(+) create mode 100644 test/management/custom-domains.tests.js diff --git a/test/management/custom-domains.tests.js b/test/management/custom-domains.tests.js new file mode 100644 index 000000000..644350719 --- /dev/null +++ b/test/management/custom-domains.tests.js @@ -0,0 +1,398 @@ +var expect = require('chai').expect; +var nock = require('nock'); + +var SRC_DIR = '../../src'; +var API_URL = 'https://tenant.auth0.com'; + +var CustomDomainsManager = require(SRC_DIR + '/management/CustomDomainsManager'); +var ArgumentError = require('rest-facade').ArgumentError; + +describe('CustomDomainsManager', function() { + before(function() { + this.token = 'TOKEN'; + this.customDomains = new CustomDomainsManager({ + headers: { authorization: 'Bearer ' + this.token }, + baseUrl: API_URL + }); + }); + + describe('instance', function() { + var methods = ['get', 'getAll', 'create', 'delete', 'verify']; + + methods.forEach(function(method) { + it('should have a ' + method + ' method', function() { + expect(this.customDomains[method]).to.exist.to.be.an.instanceOf(Function); + }); + }); + }); + + describe('#constructor', function() { + it('should error when no options are provided', function() { + expect(CustomDomainsManager).to.throw(ArgumentError, 'Must provide manager options'); + }); + + it('should throw an error when no base URL is provided', function() { + var client = CustomDomainsManager.bind(null, {}); + + expect(client).to.throw(ArgumentError, 'Must provide a base URL for the API'); + }); + + it('should throw an error when the base URL is invalid', function() { + var client = CustomDomainsManager.bind(null, { baseUrl: '' }); + + expect(client).to.throw(ArgumentError, 'The provided base URL is invalid'); + }); + }); + + describe('#getAll', function() { + beforeEach(function() { + this.request = nock(API_URL) + .get('/custom-domains') + .reply(200); + }); + + it('should accept a callback', function(done) { + this.customDomains.getAll(function() { + done(); + }); + }); + + it('should return a promise if no callback is given', function(done) { + this.customDomains + .getAll() + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .get('/custom-domains') + .reply(500); + + this.customDomains.getAll().catch(function(err) { + expect(err).to.exist; + done(); + }); + }); + + it('should pass the body of the response to the "then" handler', function(done) { + nock.cleanAll(); + + var data = [{ custom_domain_id: 'cd_0000000000000001' }]; + var request = nock(API_URL) + .get('/custom-domains') + .reply(200, data); + + this.customDomains.getAll().then(function(customDomains) { + expect(customDomains).to.be.an.instanceOf(Array); + + expect(customDomains.length).to.equal(data.length); + + expect(customDomains[0].test).to.equal(data[0].test); + + done(); + }); + }); + + it('should perform a GET request to /api/v2/custom-domains', function(done) { + var request = this.request; + + this.customDomains.getAll().then(function() { + expect(request.isDone()).to.be.true; + done(); + }); + }); + + it('should include the token in the Authorization header', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .get('/custom-domains') + .matchHeader('Authorization', 'Bearer ' + this.token) + .reply(200); + + this.customDomains.getAll().then(function() { + expect(request.isDone()).to.be.true; + done(); + }); + }); + }); + + describe('#get', function() { + beforeEach(function() { + this.data = [ + { + custom_domain_id: 'cd_0000000000000001', + domain: 'login.mycompany.com', + primary: false, + status: 'ready', + type: 'self_managed_certs', + origin_domain_name: 'mycompany_cd_0000000000000001.edge.tenants.auth0.com', + verification: { + methods: ['object'] + } + } + ]; + + this.request = nock(API_URL) + .get('/custom-domains/' + this.data[0].custom_domain_id) + .reply(200, this.data); + }); + + it('should accept a callback', function(done) { + var params = { id: this.data[0].custom_domain_id }; + + this.customDomains.get(params, done.bind(null, null)); + }); + + it('should return a promise if no callback is given', function(done) { + this.customDomains + .get({ id: this.data[0].custom_domain_id }) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should perform a POST request to /api/v2/custom-domains/cd_0000000000000001', function(done) { + var request = this.request; + + this.customDomains.get({ id: this.data[0].custom_domain_id }).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); + + it('should pass any errors to the promise catch handler', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .get('/custom-domains/' + this.data.id) + .reply(500); + + this.customDomains.get({ id: this.data.id }).catch(function(err) { + expect(err).to.exist; + + done(); + }); + }); + + it('should include the token in the Authorization header', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .get('/custom-domains/' + this.data.id) + .matchHeader('Authorization', 'Bearer ' + this.token) + .reply(200); + + this.customDomains.get({ id: this.data.id }).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); + }); + + describe('#create', function() { + var data = { + custom_domain_id: 'cd_0000000000000001', + domain: 'login.mycompany.com', + primary: false, + status: 'ready', + type: 'self_managed_certs', + origin_domain_name: 'mycompany_cd_0000000000000001.edge.tenants.auth0.com', + verification: { + methods: ['object'] + } + }; + + beforeEach(function() { + this.request = nock(API_URL) + .post('/custom-domains') + .reply(200); + }); + + it('should accept a callback', function(done) { + this.customDomains.create(data, function() { + done(); + }); + }); + + it('should return a promise if no callback is given', function(done) { + this.customDomains + .create(data) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should pass any errors to the promise catch handler', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .post('/custom-domains') + .reply(500); + + this.customDomains.create(data).catch(function(err) { + expect(err).to.exist; + + done(); + }); + }); + + it('should perform a POST request to /api/v2/custom-domains', function(done) { + var request = this.request; + + this.customDomains.create(data).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); + + it('should pass the data in the body of the request', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .post('/custom-domains', data) + .reply(200); + + this.customDomains.create(data).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); + + it('should include the token in the Authorization header', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .post('/custom-domains') + .matchHeader('Authorization', 'Bearer ' + this.token) + .reply(200); + + this.customDomains.create(data).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); + }); + + describe('#delete', function() { + var id = 'cd_0000000000000001'; + + beforeEach(function() { + this.request = nock(API_URL) + .delete('/custom-domains/' + id) + .reply(200); + }); + + it('should accept a callback', function(done) { + this.customDomains.delete({ id: id }, done.bind(null, null)); + }); + + it('should return a promise when no callback is given', function(done) { + this.customDomains.delete({ id: id }).then(done.bind(null, null)); + }); + + it('should perform a delete request to /custom-domains/' + id, function(done) { + var request = this.request; + + this.customDomains.delete({ id: id }).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); + + it('should pass any errors to the promise catch handler', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .delete('/custom-domains/' + id) + .reply(500); + + this.customDomains.delete({ id: id }).catch(function(err) { + expect(err).to.exist; + + done(); + }); + }); + + it('should include the token in the authorization header', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .delete('/custom-domains/' + id) + .matchHeader('authorization', 'Bearer ' + this.token) + .reply(200); + + this.customDomains.delete({ id: id }).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); + }); + + describe('#verify', function() { + beforeEach(function() { + this.data = { id: 'cd_0000000000000001' }; + + this.request = nock(API_URL) + .post('/custom-domains/' + this.data.id) + .reply(200, this.data); + }); + + it('should accept a callback', function(done) { + this.customDomains.verify({ id: this.data.id }, {}, done.bind(null, null)); + }); + + it('should return a promise if no callback is given', function(done) { + this.customDomains + .verify({ id: this.data.id }, {}) + .then(done.bind(null, null)) + .catch(done.bind(null, null)); + }); + + it('should perform a POST request to /api/v2/custom-domains/cd_0000000000000001', function(done) { + var request = this.request; + + this.customDomains.verify({ id: this.data.id }, {}).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); + + it('should include the new data in the body of the request', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .post('/custom-domains/' + this.data.id, this.data) + .reply(200); + + this.customDomains.verify({ id: this.data.id }, this.data).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); + + it('should pass any errors to the promise catch handler', function(done) { + nock.cleanAll(); + + var request = nock(API_URL) + .post('/custom-domains/' + this.data.id) + .reply(500); + + this.customDomains.verify({ id: this.data.id }, this.data).catch(function(err) { + expect(err).to.exist; + + done(); + }); + }); + }); +}); From d9770b0cef405970c4cd6aee7d9aa2a9e2f3c805 Mon Sep 17 00:00:00 2001 From: Steve Adams Date: Mon, 5 Nov 2018 14:15:53 +1100 Subject: [PATCH 4/8] Fix custom domains verify, should be post not patch --- src/management/CustomDomainsManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/management/CustomDomainsManager.js b/src/management/CustomDomainsManager.js index fd8d0adcd..b1c51f2ea 100644 --- a/src/management/CustomDomainsManager.js +++ b/src/management/CustomDomainsManager.js @@ -22,7 +22,7 @@ var RetryRestClient = require('../RetryRestClient'); */ var CustomDomainsManager = function(options) { if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); + throw new ArgumentError('Must provide manager options'); } if (options.baseUrl === null || options.baseUrl === undefined) { @@ -139,7 +139,7 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'get', 'resource.get'); * * @return {Promise|undefined} */ -utils.wrapPropertyMethod(CustomDomainsManager, 'verify', 'resource.get'); +utils.wrapPropertyMethod(CustomDomainsManager, 'verify', 'resource.create'); /** * Delete a Custom Domain. From b722b1aa94106d0904f235a910ba3684b5af4d86 Mon Sep 17 00:00:00 2001 From: Steve Adams Date: Mon, 5 Nov 2018 23:37:03 +1100 Subject: [PATCH 5/8] Fix Custom Domains Verify --- src/management/CustomDomainsManager.js | 21 +++++++++++++++++---- test/management/custom-domains.tests.js | 8 ++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/management/CustomDomainsManager.js b/src/management/CustomDomainsManager.js index b1c51f2ea..cf1225cab 100644 --- a/src/management/CustomDomainsManager.js +++ b/src/management/CustomDomainsManager.js @@ -46,16 +46,29 @@ var CustomDomainsManager = function(options) { /** * Provides an abstraction layer for consuming the - * {@link https://auth0.com/docs/api/v2#!/Clients Auth0 Clients endpoint}. + * {@link https://auth0.com/docs/api/v2#!/Custom_Domains Auth0 Custom Domains endpoint}. * * @type {external:RestClient} */ - var auth0RestClient = new Auth0RestClient( + var auth0CustomDomainsRestClient = new Auth0RestClient( options.baseUrl + '/custom-domains/:id', clientOptions, options.tokenProvider ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = new RetryRestClient(auth0CustomDomainsRestClient, options.retry); + + /** + * Provides an abstraction layer for consuming the + * {@link https://auth0.com/docs/api/v2#!/Custom_Domains Auth0 Custom Domains Verify endpoint}. + * + * @type {external:RestClient} + */ + var auth0VerifyRestClient = new Auth0RestClient( + options.baseUrl + '/custom-domains/:id/verify', + clientOptions, + options.tokenProvider + ); + this.vefifyResource = new RetryRestClient(auth0VerifyRestClient, options.retry); }; /** @@ -139,7 +152,7 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'get', 'resource.get'); * * @return {Promise|undefined} */ -utils.wrapPropertyMethod(CustomDomainsManager, 'verify', 'resource.create'); +utils.wrapPropertyMethod(CustomDomainsManager, 'verify', 'vefifyResource.create'); /** * Delete a Custom Domain. diff --git a/test/management/custom-domains.tests.js b/test/management/custom-domains.tests.js index 644350719..ef36502c2 100644 --- a/test/management/custom-domains.tests.js +++ b/test/management/custom-domains.tests.js @@ -342,7 +342,7 @@ describe('CustomDomainsManager', function() { this.data = { id: 'cd_0000000000000001' }; this.request = nock(API_URL) - .post('/custom-domains/' + this.data.id) + .post('/custom-domains/' + this.data.id + '/verify') .reply(200, this.data); }); @@ -357,7 +357,7 @@ describe('CustomDomainsManager', function() { .catch(done.bind(null, null)); }); - it('should perform a POST request to /api/v2/custom-domains/cd_0000000000000001', function(done) { + it('should perform a POST request to /api/v2/custom-domains/cd_0000000000000001/verify', function(done) { var request = this.request; this.customDomains.verify({ id: this.data.id }, {}).then(function() { @@ -371,7 +371,7 @@ describe('CustomDomainsManager', function() { nock.cleanAll(); var request = nock(API_URL) - .post('/custom-domains/' + this.data.id, this.data) + .post('/custom-domains/' + this.data.id + '/verify', this.data) .reply(200); this.customDomains.verify({ id: this.data.id }, this.data).then(function() { @@ -385,7 +385,7 @@ describe('CustomDomainsManager', function() { nock.cleanAll(); var request = nock(API_URL) - .post('/custom-domains/' + this.data.id) + .post('/custom-domains/' + this.data.id + '/verify') .reply(500); this.customDomains.verify({ id: this.data.id }, this.data).catch(function(err) { From f0f5266bc1ee951e8ecc4ddd17d947e0b57535a8 Mon Sep 17 00:00:00 2001 From: Steve Adams Date: Wed, 7 Nov 2018 21:59:21 +1100 Subject: [PATCH 6/8] fixes 404 with custom domains verify --- src/management/CustomDomainsManager.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/management/CustomDomainsManager.js b/src/management/CustomDomainsManager.js index cf1225cab..fea099afc 100644 --- a/src/management/CustomDomainsManager.js +++ b/src/management/CustomDomainsManager.js @@ -152,7 +152,17 @@ utils.wrapPropertyMethod(CustomDomainsManager, 'get', 'resource.get'); * * @return {Promise|undefined} */ -utils.wrapPropertyMethod(CustomDomainsManager, 'verify', 'vefifyResource.create'); +CustomDomainsManager.prototype.verify = function(params, cb) { + if (!params || !params.id) { + throw new ArgumentError('The custom domain id cannot be null or undefined'); + } + + if (cb && cb instanceof Function) { + return this.vefifyResource.create(params, {}, cb); + } + + return this.vefifyResource.create(params, {}); +}; /** * Delete a Custom Domain. From e413fe49b9f76fe8a8898ca356ce69ddd27d33f2 Mon Sep 17 00:00:00 2001 From: Steve Adams Date: Wed, 7 Nov 2018 22:03:27 +1100 Subject: [PATCH 7/8] fix tests --- test/management/custom-domains.tests.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/management/custom-domains.tests.js b/test/management/custom-domains.tests.js index ef36502c2..1afcc5433 100644 --- a/test/management/custom-domains.tests.js +++ b/test/management/custom-domains.tests.js @@ -347,7 +347,7 @@ describe('CustomDomainsManager', function() { }); it('should accept a callback', function(done) { - this.customDomains.verify({ id: this.data.id }, {}, done.bind(null, null)); + this.customDomains.verify({ id: this.data.id }, done.bind(null, null)); }); it('should return a promise if no callback is given', function(done) { @@ -360,7 +360,7 @@ describe('CustomDomainsManager', function() { it('should perform a POST request to /api/v2/custom-domains/cd_0000000000000001/verify', function(done) { var request = this.request; - this.customDomains.verify({ id: this.data.id }, {}).then(function() { + this.customDomains.verify({ id: this.data.id }).then(function() { expect(request.isDone()).to.be.true; done(); @@ -371,10 +371,10 @@ describe('CustomDomainsManager', function() { nock.cleanAll(); var request = nock(API_URL) - .post('/custom-domains/' + this.data.id + '/verify', this.data) + .post('/custom-domains/' + this.data.id + '/verify') .reply(200); - this.customDomains.verify({ id: this.data.id }, this.data).then(function() { + this.customDomains.verify({ id: this.data.id }).then(function() { expect(request.isDone()).to.be.true; done(); @@ -388,7 +388,7 @@ describe('CustomDomainsManager', function() { .post('/custom-domains/' + this.data.id + '/verify') .reply(500); - this.customDomains.verify({ id: this.data.id }, this.data).catch(function(err) { + this.customDomains.verify({ id: this.data.id }).catch(function(err) { expect(err).to.exist; done(); From 3c55b5404b9cff68144b0587680faf7f983a5997 Mon Sep 17 00:00:00 2001 From: Steve Adams Date: Sun, 11 Nov 2018 12:26:38 +1100 Subject: [PATCH 8/8] fix custom domains docs --- src/management/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/management/index.js b/src/management/index.js index 867516504..842b953c4 100644 --- a/src/management/index.js +++ b/src/management/index.js @@ -1945,7 +1945,7 @@ utils.wrapPropertyMethod(ManagementClient, 'deleteRulesConfig', 'rulesConfigs.de * @memberOf module:management.CustomDomainsManager.prototype * * @example - * management.customDomains.createCustomDomain(data, function (err) { + * management.createCustomDomain(data, function (err) { * if (err) { * // Handle error. * } @@ -1967,7 +1967,7 @@ utils.wrapPropertyMethod(ManagementClient, 'createCustomDomain', 'customDomains. * @memberOf module:management.CustomDomainsManager.prototype * * @example - * management.customDomains.getCustomDomains(function (err, customDomains) { + * management.getCustomDomains(function (err, customDomains) { * console.log(customDomains.length); * }); * @@ -1982,7 +1982,7 @@ utils.wrapPropertyMethod(ManagementClient, 'getCustomDomains', 'customDomains.ge * @memberOf module:management.CustomDomainsManager.prototype * * @example - * management.customDomains.getCustomDomain({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { + * management.getCustomDomain({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { * if (err) { * // Handle error. * } @@ -2005,7 +2005,7 @@ utils.wrapPropertyMethod(ManagementClient, 'getCustomDomain', 'customDomains.get * @memberOf module:management.CustomDomainsManager.prototype * * @example - * management.customDomains.verifyCustomDomain({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { + * management.verifyCustomDomain({ id: CUSTOM_DOMAIN_ID }, function (err, customDomain) { * if (err) { * // Handle error. * }