box-node-sdk 1.9.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,13 @@
18
18
  * server requesting the tokens.
19
19
  */
20
20
 
21
+ /**
22
+ * Parameters for creating an actor token via token exchange
23
+ * @typedef {Object} ActorParams
24
+ * @property {string} id The external identifier for the actor
25
+ * @property {string} name The display name of the actor
26
+ */
27
+
21
28
  /**
22
29
  * An object representing all token information for a single Box user.
23
30
  *
@@ -73,8 +80,11 @@ var tokenPaths = {
73
80
  };
74
81
 
75
82
  // The XFF header label - Used to give the API better information for uploads, rate-limiting, etc.
76
- var HEADER_XFF = 'X-Forwarded-For';
77
- var ACCESS_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:access_token';
83
+ const HEADER_XFF = 'X-Forwarded-For';
84
+ const ACCESS_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:access_token';
85
+ const ACTOR_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:id_token';
86
+ const BOX_JWT_AUDIENCE = 'https://api.box.com/oauth2/token';
87
+
78
88
 
79
89
  // ------------------------------------------------------------------------------
80
90
  // Private
@@ -133,7 +143,6 @@ function isValidTokenResponse(grantType, responseBody) {
133
143
  return true;
134
144
  }
135
145
 
136
-
137
146
  // ------------------------------------------------------------------------------
138
147
  // Public
139
148
  // ------------------------------------------------------------------------------
@@ -297,14 +306,12 @@ TokenManager.prototype = {
297
306
  };
298
307
  var jwtOptions = {
299
308
  algorithm: this.config.appAuth.algorithm,
300
- audience: 'https://api.box.com/oauth2/token',
309
+ audience: BOX_JWT_AUDIENCE,
301
310
  subject: id,
302
311
  issuer: this.config.clientID,
303
312
  jwtid: uuid.v4(),
304
313
  noTimestamp: !this.config.appAuth.verifyTimestamp,
305
- headers: {
306
- kid: this.config.appAuth.keyID
307
- }
314
+ keyid: this.config.appAuth.keyID
308
315
  };
309
316
  var keyParams = {
310
317
  key: this.config.appAuth.privateKey,
@@ -354,7 +361,9 @@ TokenManager.prototype = {
354
361
  * @param {string} accessToken - The valid access token to exchange
355
362
  * @param {string|string[]} scopes - The scope(s) of the new access token
356
363
  * @param {string} [resource] - The absolute URL of an API resource to restrict the new token to
357
- * @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
364
+ * @param {Object} [options] - Optional parameters
365
+ * @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
366
+ * @param {ActorParams} [options.actor] - Optional actor parameters for creating annotator tokens
358
367
  * @returns {Promise<TokenInfo>} Promise resolving to the new token info
359
368
  */
360
369
  exchangeToken: function(accessToken, scopes, resource, options) {
@@ -362,14 +371,42 @@ TokenManager.prototype = {
362
371
  grant_type: grantTypes.TOKEN_EXCHANGE,
363
372
  subject_token_type: ACCESS_TOKEN_TYPE,
364
373
  subject_token: accessToken,
365
- scope: (typeof scopes === 'string' ? scopes : scopes.join(','))
374
+ scope: (typeof scopes === 'string' ? scopes : scopes.join(' '))
366
375
  };
367
376
 
368
377
  if (resource) {
369
378
  params.resource = resource;
370
379
  }
371
380
 
372
- return this.getTokens(params, options);
381
+ if (options && options.actor) {
382
+
383
+ var payload = {
384
+ iss: this.config.clientID,
385
+ sub: options.actor.id,
386
+ aud: BOX_JWT_AUDIENCE,
387
+ jti: uuid.v4(),
388
+ box_sub_type: 'external',
389
+ name: options.actor.name
390
+ };
391
+
392
+ var jwtOptions = {
393
+ algorithm: 'none',
394
+ expiresIn: '1m',
395
+ noTimestamp: true
396
+ };
397
+
398
+ var token;
399
+ try {
400
+ token = jwt.sign(payload, 'UNUSED', jwtOptions);
401
+ } catch (jwtError) {
402
+ return Promise.reject(jwtError);
403
+ }
404
+
405
+ params.actor_token = token;
406
+ params.actor_token_type = ACTOR_TOKEN_TYPE;
407
+ }
408
+
409
+ return this.getTokens(params, options && options.tokenRequestOptions ? options.tokenRequestOptions : null);
373
410
  },
374
411
 
375
412
  /**
@@ -72,6 +72,7 @@ class PagingIterator {
72
72
  throw new Error('Cannot create paging iterator for non-paged response!');
73
73
  }
74
74
 
75
+
75
76
  var data = response.body;
76
77
 
77
78
  if (Number.isSafeInteger(data.offset)) {
@@ -81,7 +82,10 @@ class PagingIterator {
81
82
  this.nextField = PAGING_MODES.MARKER;
82
83
  this.nextValue = data.next_marker;
83
84
  } else {
84
- throw new Error('Unable to determine paging strategy for response!');
85
+ // Default to a finished marker collection when there's no field present,
86
+ // since some endpoints indicate completed paging this way
87
+ this.nextField = PAGING_MODES.MARKER;
88
+ this.nextValue = null;
85
89
  }
86
90
 
87
91
  this.limit = data.limit || data.entries.length;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "box-node-sdk",
3
3
  "author": "Box <oss@box.com>",
4
- "version": "1.9.0",
4
+ "version": "1.12.0",
5
5
  "description": "Official Box SDK for Node.js",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "bluebird": "^3.5.0",
27
27
  "http-status": "^0.2.2",
28
- "jsonwebtoken": "^5.7.0",
28
+ "jsonwebtoken": "^8.1.0",
29
29
  "merge-options": "0.0.64",
30
30
  "promise-queue": "^2.2.3",
31
31
  "request": "^2.74.0",
@@ -34,13 +34,15 @@
34
34
  "devDependencies": {
35
35
  "chai": "^4.1.1",
36
36
  "eslint": "^2.8.0",
37
- "istanbul": "^0.4.3",
38
- "jsdoc": "^3.4.0",
37
+ "jsdoc": "^3.5.5",
39
38
  "jsonlint": "~1.6.2",
40
- "leche": "^2.1.1",
41
- "mocha": "^2.4.5",
39
+ "leche": "^2.2.2",
40
+ "mocha": "^4.0.1",
42
41
  "mockery": "^1.4.1",
43
42
  "nock": "^9.0.13",
43
+ "nsp": "^3.1.0",
44
+ "nyc": "^11.3.0",
45
+ "semver": "^5.4.1",
44
46
  "shelljs": "^0.3.0",
45
47
  "shelljs-nodecli": "^0.1.1",
46
48
  "sinon": "^1.17.3"
package/.npmignore DELETED
@@ -1,4 +0,0 @@
1
- /tests/
2
- /docs/
3
- /examples/
4
- /coverage/