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.
- package/.nyc_output/b78aeaed90f4d2aa9c875464f096ca11.json +1 -0
- package/.nyc_output/d59c20738f2e8f2570dce1eebad16acf.json +1 -0
- package/.nycrc +15 -0
- package/.travis.yml +2 -0
- package/CHANGELOG.md +26 -0
- package/Makefile.js +5 -1
- package/lib/box-client.js +18 -3
- package/lib/event-stream.js +51 -51
- package/lib/managers/collaboration-whitelist.js +225 -0
- package/lib/managers/files.js +112 -20
- package/lib/managers/metadata.js +18 -0
- package/lib/managers/search.js +2 -2
- package/lib/managers/terms-of-service.js +307 -0
- package/lib/sessions/app-auth-session.js +3 -1
- package/lib/sessions/basic-session.js +3 -1
- package/lib/sessions/persistent-session.js +2 -1
- package/lib/token-manager.js +47 -10
- package/lib/util/paging-iterator.js +5 -1
- package/package.json +8 -6
- package/.npmignore +0 -4
package/lib/token-manager.js
CHANGED
|
@@ -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
|
-
|
|
77
|
-
|
|
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:
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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": "^
|
|
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
|
-
"
|
|
38
|
-
"jsdoc": "^3.4.0",
|
|
37
|
+
"jsdoc": "^3.5.5",
|
|
39
38
|
"jsonlint": "~1.6.2",
|
|
40
|
-
"leche": "^2.
|
|
41
|
-
"mocha": "^
|
|
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