Skip to content

Commit

Permalink
Merge pull request #160 from wbhob/master
Browse files Browse the repository at this point in the history
Add connection options to passwordless (#159)
  • Loading branch information
luisrudge authored Dec 11, 2017
2 parents 8900440 + 5f9e66b commit 0b9a5b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/auth/PasswordlessAuthenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var PasswordlessAuthenticator = function (options, oauth) {
* @param {Object} userData User credentials object.
* @param {String} userData.username Username.
* @param {String} userData.password Password.
* @param {String} [userData.connection=sms] Connection string: "sms" or "email".
* @param {String} [userData.client_id] Client ID.
* @param {Function} [cb] Method callback.
*
Expand All @@ -86,7 +87,7 @@ PasswordlessAuthenticator.prototype.signIn = function (userData, cb) {
var data = extend(defaultFields, userData);

// Don't let the user override the connection nor the grant type.
data.connection = 'sms';
if (!data.connection || (data.connection !== 'email' && data.connection !== 'sms')) { data.connection = 'sms'; }
data.grant_type = 'password';

if (!userData || typeof userData !== 'object') {
Expand Down
26 changes: 24 additions & 2 deletions test/auth/passwordless.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,35 @@ describe('PasswordlessAuthenticator', function () {
});


it('shouldn\'t allow the user to specify the connection', function (done) {
it('should use email connection', function (done) {
nock.cleanAll();
var data = extend({ connection: 'email' }, userData);
var request = nock(API_URL)
.post(path, function (body) {
return body.connection === 'email';
})
.reply(200);

this
.authenticator
.signIn(data)
.then(function () {
expect(request.isDone())
.to.be.true;

done();
})
.catch(done);
});


it('should allow the user to specify the connection as sms or email', function (done) {
nock.cleanAll();

var data = extend({ connection: 'TEST_CONNECTION' }, userData);
var request = nock(API_URL)
.post(path, function (body) {
return body.connection === 'sms';
return body.connection === 'sms' || body.connection === 'email';
})
.reply(200);

Expand Down

0 comments on commit 0b9a5b4

Please sign in to comment.