diff --git a/example/index.html b/example/index.html index 0d0c59ed..8d89e825 100644 --- a/example/index.html +++ b/example/index.html @@ -112,6 +112,18 @@

Login with database connection:

+
+

Login with passwordless connection:

+
+ + +
+
+ + +
+
+

Login with database connection (popup):

@@ -167,11 +179,18 @@

Console:

}); var webAuth = new auth0.WebAuth({ - domain: 'auth0-tests-auth0js.auth0.com', + domain: 'brucke.auth0.com', redirectUri: 'http://localhost:3000/example', - clientID: '3GGMIEuBPZ28lb6NBDNARaEZisqFakAs', - audience: 'https://auth0-tests-auth0js.auth0.com/userinfo', - responseType: 'token id_token' + clientID: 'k5u3o2fiAA8XweXEEX604KCwCjzjtMU6', + audience: 'https://brucke.auth0.com/userinfo', + responseType: 'token' + }); + + var webAuthPasswordless = new auth0.WebAuth({ + domain: 'brucke.auth0.com', + redirectUri: 'http://localhost:3000/example', + clientID: 'k5u3o2fiAA8XweXEEX604KCwCjzjtMU6', + responseType: 'token' }); webAuth.parseHash(function(err, data) { @@ -213,6 +232,24 @@

Console:

}, htmlConsole.dumpCallback.bind(htmlConsole)); }); + $('.passwordless-login-verify').click(function (e) { + e.preventDefault(); + webAuthPasswordless.passwordlessVerify({ + connection: 'email', + email: $('.passwordless-login-username').val(), + verificationCode: $('.passwordless-login-code').val() + }, htmlConsole.dumpCallback.bind(htmlConsole)); + }); + + $('.passwordless-login-db').click(function (e) { + e.preventDefault(); + webAuthPasswordless.passwordlessStart({ + connection: 'email', + email: $('.passwordless-login-username').val(), + send: 'code' + }, htmlConsole.dumpCallback.bind(htmlConsole)); + }); + var popupHandler; $('.popup-login-db-preload').click(function (e) { diff --git a/src/authentication/passwordless-authentication.js b/src/authentication/passwordless-authentication.js index b308f53d..c893376b 100644 --- a/src/authentication/passwordless-authentication.js +++ b/src/authentication/passwordless-authentication.js @@ -24,22 +24,14 @@ PasswordlessAuthentication.prototype.buildVerifyUrl = function (options) { /* eslint-disable */ assert.check(options, { type: 'object', message: 'options parameter is not valid' }, { connection: { type: 'string', message: 'connection option is required' }, - type: { type: 'string', message: 'type option is required', values: ['sms', 'email'], - value_message: 'type is not valid ([email,sms])' }, verificationCode: { type: 'string', message: 'verificationCode option is required' }, - phoneNumber: { required: true, type: 'string', message: 'phoneNumber option is required', - condition: function (o) { return o.type === 'sms'; } }, - email: { required: true, type: 'string', message: 'email option is required', - condition: function (o) { return o.type === 'email'; } } + phoneNumber: { optional: false, type: 'string', message: 'phoneNumber option is required', + condition: function (o) { return !o.email; } }, + email: { optional: false, type: 'string', message: 'email option is required', + condition: function (o) { return !o.phoneNumber; } } }); /* eslint-enable */ - assert.check(options, { - optional: true, - type: 'object', - message: 'options parameter is not valid' - }); - params = objectHelper.merge(this.baseOptions, [ 'clientID', 'responseType', @@ -49,8 +41,6 @@ PasswordlessAuthentication.prototype.buildVerifyUrl = function (options) { 'audience' ]).with(options); - params = objectHelper.blacklist(params, ['type']); - // eslint-disable-next-line if (this.baseOptions._sendTelemetry) { params.auth0Client = this.request.getTelemetryData(); @@ -73,25 +63,22 @@ PasswordlessAuthentication.prototype.buildVerifyUrl = function (options) { PasswordlessAuthentication.prototype.start = function (options, cb) { var url; var body; - var cleanOption; /* eslint-disable */ assert.check(options, { type: 'object', message: 'options parameter is not valid' }, { connection: { type: 'string', message: 'connection option is required' }, - type: { type: 'string', message: 'type option is required', values: ['sms', 'email'], - value_message: 'type is not valid ([email,sms])' }, - phoneNumber: { required: true, type: 'string', message: 'phoneNumber option is required', - condition: function (o) { return o.type === 'sms'; } }, - email: { required: true, type: 'string', message: 'email option is required', - condition: function (o) { return o.type === 'email'; } }, + send: { type: 'string', message: 'send option is required', values: ['link', 'code'], + value_message: 'send is not valid ([link, code])' }, + phoneNumber: { optional: true, type: 'string', message: 'phoneNumber option is required', + condition: function (o) { return o.send === 'code' || !o.email; } }, + email: { optional: true, type: 'string', message: 'email option is required', + condition: function (o) { return o.send === 'link' || !o.phoneNumber; } }, authParams: { optional: true, type: 'object', message: 'authParams option is required' } }); /* eslint-enable */ assert.check(cb, { type: 'function', message: 'cb parameter is not valid' }); - cleanOption = objectHelper.blacklist(options, ['type']); - url = urljoin(this.baseOptions.rootUrl, 'passwordless', 'start'); body = objectHelper.merge(this.baseOptions, [ @@ -99,19 +86,19 @@ PasswordlessAuthentication.prototype.start = function (options, cb) { 'responseType', 'redirectUri', 'scope' - ]).with(cleanOption); + ]).with(options); if (body.scope) { body.authParams = body.authParams || {}; body.authParams.scope = body.scope; } - if (options.type === 'email' && body.redirectUri) { + if (body.redirectUri) { body.authParams = body.authParams || {}; body.authParams.redirect_uri = body.redirectUri; } - if (options.type === 'email' && body.responseType) { + if (body.responseType) { body.authParams = body.authParams || {}; body.authParams.response_type = body.responseType; } @@ -142,21 +129,17 @@ PasswordlessAuthentication.prototype.verify = function (options, cb) { /* eslint-disable */ assert.check(options, { type: 'object', message: 'options parameter is not valid' }, { connection: { type: 'string', message: 'connection option is required' }, - type: { type: 'string', message: 'type option is required', values: ['sms', 'email'], - value_message: 'type is not valid ([email,sms])' }, verificationCode: { type: 'string', message: 'verificationCode option is required' }, - phoneNumber: { required: true, type: 'string', message: 'phoneNumber option is required', - condition: function (o) { return o.type === 'sms'; } }, - email: { required: true, type: 'string', message: 'email option is required', - condition: function (o) { return o.type === 'email'; } } + phoneNumber: { optional: false, type: 'string', message: 'phoneNumber option is required', + condition: function (o) { return !o.email; } }, + email: { optional: false, type: 'string', message: 'email option is required', + condition: function (o) { return !o.phoneNumber; } } }); /* eslint-enable */ assert.check(cb, { type: 'function', message: 'cb parameter is not valid' }); - cleanOption = objectHelper.blacklist(options, ['type']); - - cleanOption = objectHelper.toSnakeCase(cleanOption, ['auth0Client']); + cleanOption = objectHelper.toSnakeCase(options, ['auth0Client']); url = urljoin(this.baseOptions.rootUrl, 'passwordless', 'verify'); diff --git a/test/authentication/passwordless.test.js b/test/authentication/passwordless.test.js index aff185fc..09ca29ae 100644 --- a/test/authentication/passwordless.test.js +++ b/test/authentication/passwordless.test.js @@ -37,50 +37,32 @@ describe('auth0.authentication', function () { }); }); - it('should check that options.type is passed', function () { + it('should check that options.send is passed', function () { var _this = this; expect(function () { _this.auth0.passwordless.start({ connection: 'bla' }); }).to.throwException(function (e) { - expect(e.message).to.be('type option is required'); + expect(e.message).to.be('send option is required'); }); }); - it('should check that options.type is valid', function () { + it('should check that options.send is valid', function () { var _this = this; expect(function () { - _this.auth0.passwordless.start({ connection: 'bla', type: 'blabla' }); + _this.auth0.passwordless.start({ connection: 'bla', send: 'blabla' }); }).to.throwException(function (e) { - expect(e.message).to.be('type is not valid ([email,sms])'); + expect(e.message).to.be('send is not valid ([link, code])'); }); }); it('should check that cb is valid', function () { var _this = this; expect(function () { - _this.auth0.passwordless.start({ connection: 'bla', type: 'email', email: 'me@example.com' }); + _this.auth0.passwordless.start({ connection: 'bla', send: 'code', email: 'me@example.com' }); }).to.throwException(function (e) { expect(e.message).to.be('cb parameter is not valid'); }); }); - - it('should check that email is sent', function () { - var _this = this; - expect(function () { - _this.auth0.passwordless.start({ connection: 'bla', type: 'email' }, function () {}); - }).to.throwException(function (e) { - expect(e.message).to.be('email option is required'); - }); - }); - - it('should check that phoneNumber is sent', function () { - var _this = this; - expect(function () { - _this.auth0.passwordless.start({ connection: 'bla', type: 'sms' }, function () {}); - }).to.throwException(function (e) { - expect(e.message).to.be('phoneNumber option is required'); - }); - }); }); context('passwordless verify options', function () { @@ -117,14 +99,14 @@ describe('auth0.authentication', function () { expect(function () { _this.auth0.passwordless.verify({ connection: 'bla' }); }).to.throwException(function (e) { - expect(e.message).to.be('type option is required'); + expect(e.message).to.be('verificationCode option is required'); }); }); it('should check that options.verificationCode is passed', function () { var _this = this; expect(function () { - _this.auth0.passwordless.verify({ connection: 'bla', type: 'email' }); + _this.auth0.passwordless.verify({ connection: 'bla', send: 'code' }); }).to.throwException(function (e) { expect(e.message).to.be('verificationCode option is required'); }); @@ -133,16 +115,16 @@ describe('auth0.authentication', function () { it('should check that options.type is valid', function () { var _this = this; expect(function () { - _this.auth0.passwordless.verify({ connection: 'bla', type: 'blabla', verificationCode: 'asdfasd' }); + _this.auth0.passwordless.verify({ connection: 'bla', verificationCode: 'asdfasd' }); }).to.throwException(function (e) { - expect(e.message).to.be('type is not valid ([email,sms])'); + expect(e.message).to.be('phoneNumber option is required'); }); }); it('should check that cb is valid', function () { var _this = this; expect(function () { - _this.auth0.passwordless.verify({ connection: 'bla', type: 'email', verificationCode: 'asdfasd', email: 'me@example.com' }); + _this.auth0.passwordless.verify({ connection: 'bla', send: 'link', verificationCode: 'asdfasd', email: 'me@example.com' }); }).to.throwException(function (e) { expect(e.message).to.be('cb parameter is not valid'); }); @@ -151,16 +133,16 @@ describe('auth0.authentication', function () { it('should check that email is sent', function () { var _this = this; expect(function () { - _this.auth0.passwordless.verify({ connection: 'bla', type: 'email', verificationCode: 'asdfasd' }, function () {}); + _this.auth0.passwordless.verify({ connection: 'bla', send: 'code', verificationCode: 'asdfasd' }, function () {}); }).to.throwException(function (e) { - expect(e.message).to.be('email option is required'); + expect(e.message).to.be('phoneNumber option is required'); }); }); it('should check that phoneNumber is sent', function () { var _this = this; expect(function () { - _this.auth0.passwordless.verify({ connection: 'bla', type: 'sms', verificationCode: 'asdfasd' }, function () {}); + _this.auth0.passwordless.verify({ connection: 'bla', send: 'code', verificationCode: 'asdfasd' }, function () {}); }).to.throwException(function (e) { expect(e.message).to.be('phoneNumber option is required'); }); @@ -190,6 +172,7 @@ describe('auth0.authentication', function () { client_id: '...', connection: 'the_connection', email: 'me@example.com', + send: 'link', authParams: { redirect_uri: 'http://page.com/callback', response_type: 'code' @@ -209,7 +192,7 @@ describe('auth0.authentication', function () { this.auth0.passwordless.start({ connection: 'the_connection', email: 'me@example.com', - type: 'email' + send: 'link' }, function (err, data) { expect(err).to.be(null); expect(data).to.eql({ @@ -227,6 +210,7 @@ describe('auth0.authentication', function () { client_id: '...', connection: 'the_connection', email: 'me@example.com', + send: 'code', authParams: { scope: 'openid email', redirect_uri: 'http://page.com/callback', @@ -247,7 +231,7 @@ describe('auth0.authentication', function () { this.auth0.passwordless.start({ connection: 'the_connection', email: 'me@example.com', - type: 'email', + send: 'code', scope: 'openid email' }, function (err, data) { expect(err).to.be(null); @@ -297,7 +281,6 @@ describe('auth0.authentication', function () { this.auth0.passwordless.verify({ connection: 'the_connection', phoneNumber: '123456', - type: 'sms', verificationCode: 'abc' }, function (err, data) { expect(err).to.be(null); @@ -331,7 +314,6 @@ describe('auth0.authentication', function () { this.auth0.passwordless.verify({ connection: 'the_connection', email: 'me@example.com', - type: 'email', verificationCode: 'abc' }, function (err, data) { expect(err).to.be(null); diff --git a/test/helper/object.test.js b/test/helper/object.test.js index e19fc153..730202ef 100644 --- a/test/helper/object.test.js +++ b/test/helper/object.test.js @@ -420,7 +420,7 @@ describe('helpers', function () { }); }); - it.only('should not breack the string', function () { + it('should not breack the string', function () { var object = "some random string"; var newObject = objectHelper.toCamelCase(object); diff --git a/test/web-auth/popup.test.js b/test/web-auth/popup.test.js index 70df4dd6..0f80859f 100644 --- a/test/web-auth/popup.test.js +++ b/test/web-auth/popup.test.js @@ -231,7 +231,6 @@ describe('auth0.WebAuth.popup', function () { }); this.auth0.popup.passwordlessVerify({ - type: 'sms', connection: 'the_connection', phoneNumber: '+5491178786555', verificationCode: '123' @@ -298,7 +297,6 @@ describe('auth0.WebAuth.popup', function () { }); this.auth0.popup.passwordlessVerify({ - type: 'email', connection: 'the_connection', email: 'test@example.com', verificationCode: '123' @@ -339,7 +337,6 @@ describe('auth0.WebAuth.popup', function () { }); this.auth0.popup.passwordlessVerify({ - type: 'sms', connection: 'the_connection', phoneNumber: '+5491178786555', verificationCode: '123' diff --git a/test/web-auth/redirect.test.js b/test/web-auth/redirect.test.js index a8a07fce..3a085196 100644 --- a/test/web-auth/redirect.test.js +++ b/test/web-auth/redirect.test.js @@ -432,7 +432,6 @@ describe('auth0.WebAuth.redirect', function () { this.auth0.passwordlessVerify({ connection: 'the_connection', phoneNumber: '123456', - type: 'sms', verificationCode: 'abc' }, function (err) {}); }); @@ -482,7 +481,6 @@ describe('auth0.WebAuth.redirect', function () { this.auth0.passwordlessVerify({ connection: 'the_connection', phoneNumber: '123456', - type: 'sms', verificationCode: 'abc' }, function (err) {}); }); @@ -526,7 +524,6 @@ describe('auth0.WebAuth.redirect', function () { this.auth0.passwordlessVerify({ connection: 'the_connection', phoneNumber: '123456', - type: 'sms', verificationCode: 'abc' }, function (err) { expect(err).to.eql({ diff --git a/test/web-auth/web-auth.test.js b/test/web-auth/web-auth.test.js index dc874331..f48980d3 100644 --- a/test/web-auth/web-auth.test.js +++ b/test/web-auth/web-auth.test.js @@ -546,7 +546,12 @@ describe('auth0.WebAuth', function () { body: { client_id: '...', connection: 'the_connection', - phone_number: '123456' + phone_number: '123456', + send: 'code', + authParams: { + redirect_uri: 'http://page.com/callback', + response_type: 'code' + } }, headers: { 'Content-Type': 'application/json' @@ -562,7 +567,7 @@ describe('auth0.WebAuth', function () { this.auth0.passwordlessStart({ connection: 'the_connection', phoneNumber: '123456', - type: 'sms' + send: 'code' }, function (err, data) { expect(err).to.be(null); expect(data).to.eql({}); @@ -578,6 +583,7 @@ describe('auth0.WebAuth', function () { client_id: '...', connection: 'the_connection', email: 'me@example.com', + send: 'code', authParams: { redirect_uri: 'http://page.com/callback', response_type: 'code' @@ -597,7 +603,7 @@ describe('auth0.WebAuth', function () { this.auth0.passwordlessStart({ connection: 'the_connection', email: 'me@example.com', - type: 'email' + send: 'code' }, function (err, data) { expect(err).to.be(null); expect(data).to.eql({});