Repository: auth0/node-auth0
Pull request #315 (2018-11-11 02:19:38)

Fix Guardian Params
Change from param name `factor` to `name` in guardian calls to match the mgmt api.


Patch:
diff --git a/src/management/GuardianManager.js b/src/management/GuardianManager.js
index cf3452cd6..549be3ce1 100644
--- a/src/management/GuardianManager.js
+++ b/src/management/GuardianManager.js
@@ -69,7 +69,7 @@ var GuardianManager = function(options) {
    * @type {external:RestClient}
    */
   var guardianFactorsAuth0RestClient = new Auth0RestClient(
-    options.baseUrl + '/guardian/factors/:factor',
+    options.baseUrl + '/guardian/factors/:name',
     clientOptions,
     options.tokenProvider
   );
@@ -81,7 +81,7 @@ var GuardianManager = function(options) {
    * @type {external:RestClient}
    */
   var guardianFactorsTemplatesAuth0RestClient = new Auth0RestClient(
-    options.baseUrl + '/guardian/factors/:factor/templates',
+    options.baseUrl + '/guardian/factors/:name/templates',
     clientOptions,
     options.tokenProvider
   );
@@ -96,7 +96,7 @@ var GuardianManager = function(options) {
    * @type {external:RestClient}
    */
   var guardianFactorsProvidersAuth0RestClient = new Auth0RestClient(
-    options.baseUrl + '/guardian/factors/:factor/providers/:provider',
+    options.baseUrl + '/guardian/factors/:name/providers/:provider',
     clientOptions,
     options.tokenProvider
   );
@@ -183,7 +183,7 @@ utils.wrapPropertyMethod(GuardianManager, 'getFactors', 'factors.getAll');
  * @method    getFactorProvider
  * @memberOf  module:management.GuardianManager.prototype
  *
- * management.guardian.getFactorProvider({ factor: 'sms', provider: 'twilio'}, function (err, provider) {
+ * management.guardian.getFactorProvider({ name: 'sms', provider: 'twilio'}, function (err, provider) {
  *   console.log(provider);
  * });
  *
@@ -200,7 +200,7 @@ utils.wrapPropertyMethod(GuardianManager, 'getFactorProvider', 'factorsProviders
  * @method    updateFactorProvider
  * @memberOf  module:management.GuardianManager.prototype
  *
- * management.guardian.updateFactorProvider({ factor: 'sms', provider: 'twilio' }, {
+ * management.guardian.updateFactorProvider({ name: 'sms', provider: 'twilio' }, {
  *  messaging_service_sid: 'XXXXXXXXXXXXXX',
  *  auth_token: 'XXXXXXXXXXXXXX',
  *  sid: 'XXXXXXXXXXXXXX'
@@ -222,7 +222,7 @@ utils.wrapPropertyMethod(GuardianManager, 'updateFactorProvider', 'factorsProvid
  * @method    getFactorTemplates
  * @memberOf  module:management.GuardianManager.prototype
  *
- * management.guardian.getFactorTemplates({ factor: 'sms' }, function (err, templates) {
+ * management.guardian.getFactorTemplates({ name: 'sms' }, function (err, templates) {
  *   console.log(templates);
  * });
  *
@@ -239,7 +239,7 @@ utils.wrapPropertyMethod(GuardianManager, 'getFactorTemplates', 'factorsTemplate
  * @method    updateFactorTemplates
  * @memberOf  module:management.GuardianManager.prototype
  *
- * management.guardian.updateFactorProvider({ factor: 'sms' }, {
+ * management.guardian.updateFactorProvider({ name: 'sms' }, {
  *  enrollment_message: "{{code}} is your verification code for {{tenant.friendly_name}}. Please enter this code to verify your enrollment.",
  *  verification_message: "{{code}} is your verification code for {{tenant.friendly_name}}"
  * }, function(err, templates) {
@@ -260,7 +260,7 @@ utils.wrapPropertyMethod(GuardianManager, 'updateFactorTemplates', 'factorsTempl
  * @method    updateFactor
  * @memberOf  module:management.GuardianManager.prototype
  *
- * management.guardian.updateFactor({ factor: 'sms' }, {
+ * management.guardian.updateFactor({ name: 'sms' }, {
  *  enabled: true
  * }, function(err, factor) {
  *  console.log(factor);
diff --git a/src/management/index.js b/src/management/index.js
index 95711e72f..598c66a85 100644
--- a/src/management/index.js
+++ b/src/management/index.js
@@ -1972,7 +1972,7 @@ utils.wrapPropertyMethod(ManagementClient, 'getGuardianFactors', 'guardian.facto
  * @method    getGuardianFactorProvider
  * @memberOf  module:management.GuardianManager.prototype
  *
- * management.getFactorProvider({ factor: 'sms', provider: 'twilio'}, function (err, provider) {
+ * management.getFactorProvider({ name: 'sms', provider: 'twilio'}, function (err, provider) {
  *   console.log(provider);
  * });
  *
@@ -1993,7 +1993,7 @@ utils.wrapPropertyMethod(
  * @method    updateFactorProvider
  * @memberOf  module:management.GuardianManager.prototype
  *
- * management.updateGuardianFactorProvider({ factor: 'sms', provider: 'twilio' }, {
+ * management.updateGuardianFactorProvider({ name: 'sms', provider: 'twilio' }, {
  *  messaging_service_sid: 'XXXXXXXXXXXXXX',
  *  auth_token: 'XXXXXXXXXXXXXX',
  *  sid: 'XXXXXXXXXXXXXX'
@@ -2019,7 +2019,7 @@ utils.wrapPropertyMethod(
  * @method    getGuardianFactorTemplates
  * @memberOf  module:management.GuardianManager.prototype
  *
- * management.getGuardianFactorTemplates({ factor: 'sms' }, function (err, templates) {
+ * management.getGuardianFactorTemplates({ name: 'sms' }, function (err, templates) {
  *   console.log(templates);
  * });
  *
@@ -2040,7 +2040,7 @@ utils.wrapPropertyMethod(
  * @method    updateGuardianFactorTemplates
  * @memberOf  module:management.GuardianManager.prototype
  *
- * management.updateGuardianFactorTemplates({ factor: 'sms' }, {
+ * management.updateGuardianFactorTemplates({ name: 'sms' }, {
  *  enrollment_message: "{{code}} is your verification code for {{tenant.friendly_name}}. Please enter this code to verify your enrollment.",
  *  verification_message: "{{code}} is your verification code for {{tenant.friendly_name}}"
  * }, function(err, templates) {
@@ -2065,7 +2065,7 @@ utils.wrapPropertyMethod(
  * @method    updateGuardianFactor
  * @memberOf  module.GuardianManager.prototype
  *
- * management.updateGuardianFactor({ factor: 'sms' }, {
+ * management.updateGuardianFactor({ name: 'sms' }, {
  *  enabled: true
  * }, function(err, factor) {
  *  console.log(factor);


Test patch:
diff --git a/test/management/guardian.tests.js b/test/management/guardian.tests.js
index 89c98f778..b3fd95731 100644
--- a/test/management/guardian.tests.js
+++ b/test/management/guardian.tests.js
@@ -344,7 +344,7 @@ describe('GuardianManager', function() {
 
   describe('#getFactorProvider', function() {
     beforeEach(function() {
-      this.params = { factor: 'sms', provider: 'twilio' };
+      this.params = { name: 'sms', provider: 'twilio' };
       this.data = {
         from: '+1223323',
         messaging_service_sid: '5dEkAiHLPCuQ1uJj4qNXcAnERFAL6cpq',
@@ -353,7 +353,7 @@ describe('GuardianManager', function() {
       };
 
       this.request = nock(API_URL)
-        .get('/guardian/factors/' + this.params.factor + '/providers/' + this.params.provider)
+        .get('/guardian/factors/' + this.params.name + '/providers/' + this.params.provider)
         .reply(200, this.data);
     });
 
@@ -382,7 +382,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .get('guardian/factors/' + this.params.factor + '/providers/' + this.params.provider)
+        .get('guardian/factors/' + this.params.name + '/providers/' + this.params.provider)
         .reply(500);
 
       this.guardian.getFactorProvider(this.params).catch(function(err) {
@@ -396,7 +396,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .get('/guardian/factors/' + this.params.factor + '/providers/' + this.params.provider)
+        .get('/guardian/factors/' + this.params.name + '/providers/' + this.params.provider)
         .matchHeader('Authorization', 'Bearer ' + this.token)
         .reply(200);
 
@@ -410,7 +410,7 @@ describe('GuardianManager', function() {
 
   describe('#updateFactorProvider', function() {
     beforeEach(function() {
-      this.params = { factor: 'sms', provider: 'twilio' };
+      this.params = { name: 'sms', provider: 'twilio' };
       this.data = {
         from: '+1223323',
         messaging_service_sid: '5dEkAiHLPCuQ1uJj4qNXcAnERFAL6cpq',
@@ -432,7 +432,7 @@ describe('GuardianManager', function() {
 
     it('should perform a PUT request to /api/v2/guardian/factors/sms/providers/twilio', function(done) {
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor + '/providers/' + this.params.provider)
+        .put('/guardian/factors/' + this.params.name + '/providers/' + this.params.provider)
         .reply(200, this.data);
 
       this.guardian.updateFactorProvider(this.params, this.data).then(function() {
@@ -446,7 +446,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor + '/providers/' + this.params.provider)
+        .put('/guardian/factors/' + this.params.name + '/providers/' + this.params.provider)
         .reply(200);
 
       this.guardian.updateFactorProvider(this.params, this.data).then(function() {
@@ -460,7 +460,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor + '/providers/' + this.params.provider)
+        .put('/guardian/factors/' + this.params.name + '/providers/' + this.params.provider)
         .reply(500);
 
       this.guardian.updateFactorProvider(this.params, this.data).catch(function(err) {
@@ -474,7 +474,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor + '/providers/' + this.params.provider)
+        .put('/guardian/factors/' + this.params.name + '/providers/' + this.params.provider)
         .matchHeader('Authorization', 'Bearer ' + this.token)
         .reply(200);
 
@@ -488,7 +488,7 @@ describe('GuardianManager', function() {
 
   describe('#getFactorTemplates', function() {
     beforeEach(function() {
-      this.params = { factor: 'sms' };
+      this.params = { name: 'sms' };
 
       this.data = {
         enrollment_message:
@@ -554,7 +554,7 @@ describe('GuardianManager', function() {
 
   describe('#updateFactorTemplates', function() {
     beforeEach(function() {
-      this.params = { factor: 'sms' };
+      this.params = { name: 'sms' };
       this.data = {
         enrollment_message:
           '{{code}} is your verification code for {{tenant.friendly_name}}. Please enter this code to verify your enrollment.',
@@ -575,7 +575,7 @@ describe('GuardianManager', function() {
 
     it('should perform a PUT request to /api/v2/guardian/factors/sms/templates', function(done) {
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor + '/templates')
+        .put('/guardian/factors/' + this.params.name + '/templates')
         .reply(200, this.data);
 
       this.guardian.updateFactorTemplates(this.params, this.data).then(function() {
@@ -589,7 +589,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor + '/templates')
+        .put('/guardian/factors/' + this.params.name + '/templates')
         .reply(200);
 
       this.guardian.updateFactorTemplates(this.params, this.data).then(function() {
@@ -603,7 +603,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor + '/templates')
+        .put('/guardian/factors/' + this.params.name + '/templates')
         .reply(500);
 
       this.guardian.updateFactorTemplates(this.params, this.data).catch(function(err) {
@@ -617,7 +617,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor + '/templates')
+        .put('/guardian/factors/' + this.params.name + '/templates')
         .matchHeader('Authorization', 'Bearer ' + this.token)
         .reply(200);
 
@@ -631,7 +631,7 @@ describe('GuardianManager', function() {
 
   describe('#updateFactor', function() {
     beforeEach(function() {
-      this.params = { factor: 'sms' };
+      this.params = { name: 'sms' };
       this.data = {
         enabled: true
       };
@@ -650,7 +650,7 @@ describe('GuardianManager', function() {
 
     it('should perform a PUT request to /api/v2/guardian/factors/sms', function(done) {
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor)
+        .put('/guardian/factors/' + this.params.name)
         .reply(200, this.data);
 
       this.guardian.updateFactor(this.params, this.data).then(function() {
@@ -664,7 +664,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor)
+        .put('/guardian/factors/' + this.params.name)
         .reply(200);
 
       this.guardian.updateFactor(this.params, this.data).then(function() {
@@ -678,7 +678,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor)
+        .put('/guardian/factors/' + this.params.name)
         .reply(500);
 
       this.guardian.updateFactor(this.params, this.data).catch(function(err) {
@@ -692,7 +692,7 @@ describe('GuardianManager', function() {
       nock.cleanAll();
 
       var request = nock(API_URL)
-        .put('/guardian/factors/' + this.params.factor)
+        .put('/guardian/factors/' + this.params.name)
         .matchHeader('Authorization', 'Bearer ' + this.token)
         .reply(200);