Skip to content

Commit ea16678

Browse files
authored
Merge pull request #124 from particle-iot/feature/ch69020/token-list-otp
feature/ch69020/token-list-otp
2 parents b224e36 + 9dea711 commit ea16678

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/Particle.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,16 @@ class Particle {
345345
* @param {Object} options Options for this API call
346346
* @param {String} options.username Username
347347
* @param {String} options.password Password
348+
* @param {String} options.otp Current one-time-password generated from the authentication application
348349
* @param {Object} [options.headers] Key/Value pairs like `{ 'X-FOO': 'foo', X-BAR: 'bar' }` to send as headers.
349350
* @param {Object} [options.context] Request context
350351
* @returns {Promise} A promise
351352
*/
352-
listAccessTokens({ username, password, headers, context }){
353+
listAccessTokens({ username, password, otp, headers, context }){
353354
return this.get({
354355
uri: '/v1/access_tokens',
355356
auth: { username, password },
357+
query: otp ? { otp } : undefined,
356358
headers,
357359
context
358360
});

test/Particle.spec.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,37 @@ describe('ParticleAPI', () => {
335335
});
336336

337337
describe('.listAccessTokens', () => {
338+
let options;
339+
340+
beforeEach(() => {
341+
options = {
342+
username: props.username,
343+
password: props.password,
344+
otp: props.otp
345+
};
346+
});
347+
338348
it('sends credentials', () => {
339-
return api.listAccessTokens(props).then(({ auth }) => {
340-
auth.username.should.equal(props.username);
341-
auth.password.should.equal(props.password);
342-
});
349+
delete options.otp;
350+
return api.listAccessTokens(options)
351+
.then(({ auth, query }) => {
352+
expect(auth).to.be.an('object');
353+
expect(auth).to.have.property('username', options.username);
354+
expect(auth).to.have.property('password', options.password);
355+
expect(query).to.equal(undefined);
356+
});
357+
});
358+
359+
it('includes otp when provided', () => {
360+
return api.listAccessTokens(options)
361+
.then(({ auth, query }) => {
362+
expect(auth).to.be.an('object');
363+
expect(auth).to.have.property('username', options.username);
364+
expect(auth).to.have.property('password', options.password);
365+
expect(query).to.be.an('object');
366+
expect(query).to.have.property('otp', props.otp);
367+
expect(props.otp).to.be.a('string').with.lengthOf(6);
368+
});
343369
});
344370
});
345371

0 commit comments

Comments
 (0)