Repository: auth0/auth0.js
Pull request #459 (2017-06-20 18:28:08)

Fix passwordless inside hosted login page


Patch:
diff --git a/src/authentication/passwordless-authentication.js b/src/authentication/passwordless-authentication.js
index 2ecaf60..a4a3732 100644
--- a/src/authentication/passwordless-authentication.js
+++ b/src/authentication/passwordless-authentication.js
@@ -48,7 +48,12 @@ PasswordlessAuthentication.prototype.buildVerifyUrl = function(options) {
       'responseMode',
       'redirectUri',
       'scope',
-      'audience'
+      'audience',
+      '_csrf',
+      'state',
+      '_intstate',
+      'protocol',
+      'nonce'
     ])
     .with(options);
 
@@ -166,7 +171,14 @@ PasswordlessAuthentication.prototype.verify = function(options, cb) {
 
   assert.check(cb, { type: 'function', message: 'cb parameter is not valid' });
 
-  cleanOption = objectHelper.toSnakeCase(options, ['auth0Client']);
+  cleanOption = objectHelper.pick(options, [
+    'connection',
+    'verificationCode',
+    'phoneNumber',
+    'email',
+    'auth0Client'
+  ]);
+  cleanOption = objectHelper.toSnakeCase(cleanOption, ['auth0Client']);
 
   url = urljoin(this.baseOptions.rootUrl, 'passwordless', 'verify');
 
diff --git a/src/web-auth/index.js b/src/web-auth/index.js
index 3de0d19..65ad56c 100644
--- a/src/web-auth/index.js
+++ b/src/web-auth/index.js
@@ -263,7 +263,7 @@ WebAuth.prototype.renewAuth = function(options, cb) {
       'audience',
       '_csrf',
       'state',
-      '_instate',
+      '_intstate',
       'nonce'
     ])
     .with(options);
@@ -373,7 +373,7 @@ WebAuth.prototype.authorize = function(options) {
       'audience',
       '_csrf',
       'state',
-      '_instate',
+      '_intstate',
       'nonce'
     ])
     .with(options);
diff --git a/src/web-auth/popup.js b/src/web-auth/popup.js
index 8512438..b078860 100644
--- a/src/web-auth/popup.js
+++ b/src/web-auth/popup.js
@@ -125,7 +125,7 @@ Popup.prototype.authorize = function(options, cb) {
       'redirectUri',
       '_csrf',
       'state',
-      '_instate',
+      '_intstate',
       'nonce'
     ])
     .with(objectHelper.blacklist(options, ['popupHandler']));
@@ -215,7 +215,7 @@ Popup.prototype.loginWithCredentials = function(options, cb) {
       'audience',
       '_csrf',
       'state',
-      '_instate',
+      '_intstate',
       'nonce'
     ])
     .with(objectHelper.blacklist(options, ['popupHandler']));
diff --git a/src/web-auth/redirect.js b/src/web-auth/redirect.js
index c43a3c1..5820e20 100644
--- a/src/web-auth/redirect.js
+++ b/src/web-auth/redirect.js
@@ -49,7 +49,7 @@ Redirect.prototype.loginWithCredentials = function(options, cb) {
       'audience',
       '_csrf',
       'state',
-      '_instate',
+      '_intstate',
       'nonce'
     ])
     .with(options);


Test patch:
diff --git a/test/authentication/passwordless.test.js b/test/authentication/passwordless.test.js
index db853df..69b77c2 100644
--- a/test/authentication/passwordless.test.js
+++ b/test/authentication/passwordless.test.js
@@ -342,5 +342,77 @@ describe('auth0.authentication', function() {
         }
       );
     });
+
+    it('should call passwordless email verify removing extra parameters', function(done) {
+      stub(request, 'post', function(url) {
+        expect(url).to.be('https://me.auth0.com/passwordless/verify');
+        return new RequestMock({
+          body: {
+            connection: 'the_connection',
+            email: 'me@example.com',
+            verification_code: 'abc'
+          },
+          headers: {
+            'Content-Type': 'application/json'
+          },
+          cb: function(cb) {
+            cb(null, {
+              body: {}
+            });
+          }
+        });
+      });
+
+      this.auth0.passwordless.verify(
+        {
+          connection: 'the_connection',
+          email: 'me@example.com',
+          verificationCode: 'abc',
+          state: 'random',
+          response_type: 'token'
+        },
+        function(err, data) {
+          expect(err).to.be(null);
+          expect(data).to.eql({});
+          done();
+        }
+      );
+    });
+
+    it('should call passwordless sms verify removing extra parameters', function(done) {
+      stub(request, 'post', function(url) {
+        expect(url).to.be('https://me.auth0.com/passwordless/verify');
+        return new RequestMock({
+          body: {
+            connection: 'sms',
+            phone_number: '+1234567890',
+            verification_code: 'abc'
+          },
+          headers: {
+            'Content-Type': 'application/json'
+          },
+          cb: function(cb) {
+            cb(null, {
+              body: {}
+            });
+          }
+        });
+      });
+
+      this.auth0.passwordless.verify(
+        {
+          connection: 'sms',
+          phoneNumber: '+1234567890',
+          verificationCode: 'abc',
+          state: 'random',
+          response_type: 'token'
+        },
+        function(err, data) {
+          expect(err).to.be(null);
+          expect(data).to.eql({});
+          done();
+        }
+      );
+    });
   });
 });