@webex/webex-core 3.13.0-next.1 → 3.13.0-next.10
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/.repo-context.json +1 -1
- package/.sdd/manifest.json +14 -4
- package/AGENTS.md +2 -2
- package/README.md +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/credentials-config.js +9 -1
- package/dist/credentials-config.js.map +1 -1
- package/dist/interceptors/auth.js +10 -1
- package/dist/interceptors/auth.js.map +1 -1
- package/dist/lib/batcher.js +1 -1
- package/dist/lib/credentials/credentials.js +15 -2
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/token.js +23 -9
- package/dist/lib/credentials/token.js.map +1 -1
- package/dist/lib/interceptors/service.js +5 -1
- package/dist/lib/interceptors/service.js.map +1 -1
- package/dist/lib/services/catalog-auth.js +114 -0
- package/dist/lib/services/catalog-auth.js.map +1 -0
- package/dist/lib/services/services.js +46 -3
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/services-v2/services-v2.js +40 -3
- package/dist/lib/services-v2/services-v2.js.map +1 -1
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +2 -2
- package/dist/webex-core.js.map +1 -1
- package/docs/getting-started.md +2 -2
- package/package.json +13 -13
- package/src/config.js +1 -1
- package/src/credentials-config.js +9 -0
- package/src/interceptors/auth.js +14 -1
- package/src/lib/credentials/credentials.js +13 -1
- package/src/lib/credentials/docs/README.md +18 -17
- package/src/lib/credentials/token.js +15 -8
- package/src/lib/interceptors/service.js +11 -3
- package/src/lib/services/catalog-auth.js +112 -0
- package/src/lib/services/docs/README.md +4 -4
- package/src/lib/services/services.js +54 -2
- package/src/lib/services-v2/docs/README.md +4 -4
- package/src/lib/services-v2/services-v2.ts +48 -2
- package/test/fixtures/activation-email.ts +1 -1
- package/test/integration/spec/credentials/credentials.js +3 -1
- package/test/integration/spec/credentials/token.js +8 -0
- package/test/integration/spec/services/service-catalog.js +5 -0
- package/test/integration/spec/unit-browser/token.js +7 -2
- package/test/unit/spec/credentials/credentials.js +79 -0
- package/test/unit/spec/credentials/token.js +259 -6
- package/test/unit/spec/interceptors/auth.js +36 -1
- package/test/unit/spec/services/interceptors/service.js +35 -1
- package/test/unit/spec/services/services.js +318 -9
- package/test/unit/spec/services-v2/services-v2.ts +240 -13
|
@@ -150,7 +150,7 @@ describe('webex-core', () => {
|
|
|
150
150
|
|
|
151
151
|
describe('#downscope()', () => {
|
|
152
152
|
it('requires an access token', () => {
|
|
153
|
-
const token = makeToken();
|
|
153
|
+
const token = makeToken({scope: 'scopeA scopeB'});
|
|
154
154
|
|
|
155
155
|
token.unset('access_token');
|
|
156
156
|
|
|
@@ -158,7 +158,7 @@ describe('webex-core', () => {
|
|
|
158
158
|
});
|
|
159
159
|
|
|
160
160
|
it('requires an unexpired access token', () => {
|
|
161
|
-
const token = makeToken({expires: Date.now() - 10000});
|
|
161
|
+
const token = makeToken({expires: Date.now() - 10000, scope: 'scopeA scopeB'});
|
|
162
162
|
|
|
163
163
|
return assert.isRejected(
|
|
164
164
|
token.downscope('spark:kms'),
|
|
@@ -167,6 +167,15 @@ describe('webex-core', () => {
|
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
it('rejects downscope when the new scope is not super set of the available scopes', () => {
|
|
170
|
+
const token = makeToken({scope: 'scopeA scopeB'});
|
|
171
|
+
|
|
172
|
+
return assert.isRejected(
|
|
173
|
+
token.downscope('scopeX'),
|
|
174
|
+
/new scope \(scopeX\) is not subset of the available scopes \(scopeA scopeB\)/
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('rejects downscope when the new scope is not super set of the available scopes - config fallback', () => {
|
|
170
179
|
const token = makeToken();
|
|
171
180
|
token.config.scope = 'scopeY scopeZ';
|
|
172
181
|
|
|
@@ -176,11 +185,54 @@ describe('webex-core', () => {
|
|
|
176
185
|
);
|
|
177
186
|
});
|
|
178
187
|
|
|
179
|
-
it('
|
|
188
|
+
it("uses the token's scope instead of the configured scope for downscope", () => {
|
|
189
|
+
const token = makeToken({scope: 'scopeX scopeY'});
|
|
190
|
+
|
|
191
|
+
token.config.scope = 'scopeY';
|
|
192
|
+
webex.request.returns(Promise.resolve({body: {access_token: 'AT2'}}));
|
|
193
|
+
|
|
194
|
+
return token.downscope('scopeX').then(() => {
|
|
195
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
196
|
+
method: 'POST',
|
|
197
|
+
uri: token.config.tokenUrl,
|
|
198
|
+
addAuthHeader: false,
|
|
199
|
+
form: {
|
|
200
|
+
grant_type: 'urn:cisco:oauth:grant-type:scope-reduction',
|
|
201
|
+
token: 'AT',
|
|
202
|
+
scope: 'scopeX',
|
|
203
|
+
client_id: token.config.client_id,
|
|
204
|
+
self_contained_token: true,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("falls back to the configured scope for downscope", () => {
|
|
180
211
|
const token = makeToken();
|
|
181
212
|
|
|
213
|
+
token.config.scope = 'scopeX scopeY';
|
|
214
|
+
webex.request.returns(Promise.resolve({body: {access_token: 'AT2'}}));
|
|
215
|
+
|
|
216
|
+
return token.downscope('scopeX').then(() => {
|
|
217
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
218
|
+
method: 'POST',
|
|
219
|
+
uri: token.config.tokenUrl,
|
|
220
|
+
addAuthHeader: false,
|
|
221
|
+
form: {
|
|
222
|
+
grant_type: 'urn:cisco:oauth:grant-type:scope-reduction',
|
|
223
|
+
token: 'AT',
|
|
224
|
+
scope: 'scopeX',
|
|
225
|
+
client_id: token.config.client_id,
|
|
226
|
+
self_contained_token: true,
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('alphabetizes the requested scope', () => {
|
|
233
|
+
const token = makeToken({scope: 'a b c'});
|
|
234
|
+
|
|
182
235
|
webex.request.returns(Promise.resolve({body: {access_token: 'AT2'}}));
|
|
183
|
-
token.config.scope = 'a b c';
|
|
184
236
|
return token
|
|
185
237
|
.downscope('b a')
|
|
186
238
|
.then(() => assert.equal(webex.request.args[0][0].form.scope, 'a b'));
|
|
@@ -269,12 +321,13 @@ describe('webex-core', () => {
|
|
|
269
321
|
|
|
270
322
|
describe('#refresh()', () => {
|
|
271
323
|
browserOnly(it)('refreshes the access_token', () => {
|
|
272
|
-
const token = makeToken();
|
|
324
|
+
const token = makeToken({scope: 'scope1'});
|
|
273
325
|
|
|
274
326
|
webex.config.credentials.refreshCallback = sinon.stub().returns(
|
|
275
327
|
Promise.resolve({
|
|
276
328
|
access_token: 'AT2',
|
|
277
329
|
expires_in: 10000,
|
|
330
|
+
scope: 'scope1',
|
|
278
331
|
token_type: 'Fake',
|
|
279
332
|
})
|
|
280
333
|
);
|
|
@@ -285,17 +338,23 @@ describe('webex-core', () => {
|
|
|
285
338
|
|
|
286
339
|
return token.refresh().then((token2) => {
|
|
287
340
|
assert.equal(token2.access_token, 'AT2');
|
|
341
|
+
assert.equal(token2.scope, 'scope1');
|
|
342
|
+
assert.calledOnceWithExactly(webex.config.credentials.refreshCallback, webex, token, {
|
|
343
|
+
scope: undefined,
|
|
344
|
+
upgradeScope: undefined,
|
|
345
|
+
});
|
|
288
346
|
});
|
|
289
347
|
});
|
|
290
348
|
|
|
291
349
|
nodeOnly(it)('refreshes the access_token', () => {
|
|
292
|
-
const token = makeToken();
|
|
350
|
+
const token = makeToken({scope: 'scope1'});
|
|
293
351
|
|
|
294
352
|
webex.request.onCall(0).returns(
|
|
295
353
|
Promise.resolve({
|
|
296
354
|
body: {
|
|
297
355
|
access_token: 'AT2',
|
|
298
356
|
expires_in: 10000,
|
|
357
|
+
scope: 'scope1',
|
|
299
358
|
token_type: 'Fake',
|
|
300
359
|
},
|
|
301
360
|
})
|
|
@@ -303,6 +362,200 @@ describe('webex-core', () => {
|
|
|
303
362
|
|
|
304
363
|
return token.refresh().then((token2) => {
|
|
305
364
|
assert.equal(token2.access_token, 'AT2');
|
|
365
|
+
assert.equal(token2.scope, 'scope1');
|
|
366
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
367
|
+
method: 'POST',
|
|
368
|
+
uri: token.config.tokenUrl,
|
|
369
|
+
form: {
|
|
370
|
+
grant_type: 'refresh_token',
|
|
371
|
+
redirect_uri: token.config.redirect_uri,
|
|
372
|
+
refresh_token: 'RT',
|
|
373
|
+
},
|
|
374
|
+
auth: {
|
|
375
|
+
user: token.config.client_id,
|
|
376
|
+
pass: token.config.client_secret,
|
|
377
|
+
sendImmediately: true,
|
|
378
|
+
},
|
|
379
|
+
shouldRefreshAccessToken: false,
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
browserOnly(it)('refreshes the access_token with scope upgrade', () => {
|
|
385
|
+
const token = makeToken({scope: 'scope1'});
|
|
386
|
+
|
|
387
|
+
webex.config.credentials.refreshCallback = sinon.stub().returns(
|
|
388
|
+
Promise.resolve({
|
|
389
|
+
access_token: 'AT2',
|
|
390
|
+
expires_in: 10000,
|
|
391
|
+
scope: 'scope1 scope2',
|
|
392
|
+
token_type: 'Fake',
|
|
393
|
+
})
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
// FIXME this next line should be necessary. we need a better way to
|
|
397
|
+
// do config
|
|
398
|
+
token.trigger('change:config');
|
|
399
|
+
|
|
400
|
+
return token.refresh({upgradeScope: 'scope1 scope2'}).then((token2) => {
|
|
401
|
+
assert.equal(token2.access_token, 'AT2');
|
|
402
|
+
assert.equal(token2.scope, 'scope1 scope2');
|
|
403
|
+
assert.calledOnceWithExactly(webex.config.credentials.refreshCallback, webex, token, {
|
|
404
|
+
scope: undefined,
|
|
405
|
+
upgradeScope: 'scope1 scope2',
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
nodeOnly(it)('refreshes the access_token with scope upgrade', () => {
|
|
411
|
+
const token = makeToken({scope: 'scope1'});
|
|
412
|
+
|
|
413
|
+
webex.request.onCall(0).returns(
|
|
414
|
+
Promise.resolve({
|
|
415
|
+
body: {
|
|
416
|
+
access_token: 'AT2',
|
|
417
|
+
expires_in: 10000,
|
|
418
|
+
scope: 'scope1 scope2',
|
|
419
|
+
token_type: 'Fake',
|
|
420
|
+
},
|
|
421
|
+
})
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
return token.refresh({upgradeScope: 'scope1 scope2'}).then((token2) => {
|
|
425
|
+
assert.equal(token2.access_token, 'AT2');
|
|
426
|
+
assert.equal(token2.scope, 'scope1 scope2');
|
|
427
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
428
|
+
method: 'POST',
|
|
429
|
+
uri: token.config.tokenUrl,
|
|
430
|
+
form: {
|
|
431
|
+
grant_type: 'refresh_token',
|
|
432
|
+
redirect_uri: token.config.redirect_uri,
|
|
433
|
+
refresh_token: 'RT',
|
|
434
|
+
upgrade_scope: 'scope1 scope2',
|
|
435
|
+
},
|
|
436
|
+
auth: {
|
|
437
|
+
user: token.config.client_id,
|
|
438
|
+
pass: token.config.client_secret,
|
|
439
|
+
sendImmediately: true,
|
|
440
|
+
},
|
|
441
|
+
shouldRefreshAccessToken: false,
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
browserOnly(it)('refreshes the access_token with an explicit scope', () => {
|
|
447
|
+
const token = makeToken({scope: 'scope1 scope2'});
|
|
448
|
+
|
|
449
|
+
webex.config.credentials.refreshCallback = sinon.stub().resolves({
|
|
450
|
+
access_token: 'AT2',
|
|
451
|
+
expires_in: 10000,
|
|
452
|
+
scope: 'scope1',
|
|
453
|
+
token_type: 'Fake',
|
|
454
|
+
});
|
|
455
|
+
token.trigger('change:config');
|
|
456
|
+
|
|
457
|
+
return token.refresh({scope: 'scope1'}).then((token2) => {
|
|
458
|
+
assert.equal(token2.access_token, 'AT2');
|
|
459
|
+
assert.equal(token2.scope, 'scope1');
|
|
460
|
+
assert.calledOnceWithExactly(webex.config.credentials.refreshCallback, webex, token, {
|
|
461
|
+
scope: 'scope1',
|
|
462
|
+
upgradeScope: undefined,
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
nodeOnly(it)('refreshes the access_token with an explicit scope', () => {
|
|
468
|
+
const token = makeToken({scope: 'scope1 scope2'});
|
|
469
|
+
|
|
470
|
+
webex.request.resolves({
|
|
471
|
+
body: {
|
|
472
|
+
access_token: 'AT2',
|
|
473
|
+
expires_in: 10000,
|
|
474
|
+
scope: 'scope1',
|
|
475
|
+
token_type: 'Fake',
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
return token.refresh({scope: 'scope1'}).then((token2) => {
|
|
480
|
+
assert.equal(token2.access_token, 'AT2');
|
|
481
|
+
assert.equal(token2.scope, 'scope1');
|
|
482
|
+
assert.calledOnceWithExactly(webex.request, {
|
|
483
|
+
method: 'POST',
|
|
484
|
+
uri: token.config.tokenUrl,
|
|
485
|
+
form: {
|
|
486
|
+
grant_type: 'refresh_token',
|
|
487
|
+
redirect_uri: token.config.redirect_uri,
|
|
488
|
+
refresh_token: 'RT',
|
|
489
|
+
scope: 'scope1',
|
|
490
|
+
},
|
|
491
|
+
auth: {
|
|
492
|
+
user: token.config.client_id,
|
|
493
|
+
pass: token.config.client_secret,
|
|
494
|
+
sendImmediately: true,
|
|
495
|
+
},
|
|
496
|
+
shouldRefreshAccessToken: false,
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
[
|
|
502
|
+
{
|
|
503
|
+
description: 'prefers the returned scope over an explicit scope',
|
|
504
|
+
options: {scope: 'scope1 scope2'},
|
|
505
|
+
responseScope: 'scope1',
|
|
506
|
+
expectedScope: 'scope1',
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
description: 'uses the explicit scope when the response omits scope',
|
|
510
|
+
options: {scope: 'scope1'},
|
|
511
|
+
responseScope: undefined,
|
|
512
|
+
expectedScope: 'scope1',
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
description:
|
|
516
|
+
'retains the old scope when neither the request nor response supplies scope',
|
|
517
|
+
options: {},
|
|
518
|
+
responseScope: undefined,
|
|
519
|
+
expectedScope: 'scope1 scope2',
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
description: 'does not assume an upgrade succeeded when the response omits scope',
|
|
523
|
+
options: {upgradeScope: 'scope1 scope2 scope3'},
|
|
524
|
+
responseScope: undefined,
|
|
525
|
+
expectedScope: 'scope1 scope2',
|
|
526
|
+
},
|
|
527
|
+
].forEach(({description, options, responseScope, expectedScope}) => {
|
|
528
|
+
browserOnly(it)(description, () => {
|
|
529
|
+
const token = makeToken({scope: 'scope1 scope2'});
|
|
530
|
+
|
|
531
|
+
webex.config.credentials.refreshCallback = sinon.stub().resolves({
|
|
532
|
+
access_token: 'AT2',
|
|
533
|
+
expires_in: 10000,
|
|
534
|
+
scope: responseScope,
|
|
535
|
+
token_type: 'Fake',
|
|
536
|
+
});
|
|
537
|
+
token.trigger('change:config');
|
|
538
|
+
|
|
539
|
+
return token.refresh(options).then((token2) => {
|
|
540
|
+
assert.equal(token2.scope, expectedScope);
|
|
541
|
+
});
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
nodeOnly(it)(description, () => {
|
|
545
|
+
const token = makeToken({scope: 'scope1 scope2'});
|
|
546
|
+
|
|
547
|
+
webex.request.resolves({
|
|
548
|
+
body: {
|
|
549
|
+
access_token: 'AT2',
|
|
550
|
+
expires_in: 10000,
|
|
551
|
+
scope: responseScope,
|
|
552
|
+
token_type: 'Fake',
|
|
553
|
+
},
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
return token.refresh(options).then((token2) => {
|
|
557
|
+
assert.equal(token2.scope, expectedScope);
|
|
558
|
+
});
|
|
306
559
|
});
|
|
307
560
|
});
|
|
308
561
|
|
|
@@ -239,7 +239,7 @@ describe('webex-core', () => {
|
|
|
239
239
|
beforeEach(() => {
|
|
240
240
|
services = {
|
|
241
241
|
hydra: 'https://hydra-a.wbx.com',
|
|
242
|
-
u2c: 'https://u2c.
|
|
242
|
+
u2c: 'https://u2c.svc.webex.com/u2c/api/v1',
|
|
243
243
|
example: 'https://service.example.com',
|
|
244
244
|
};
|
|
245
245
|
|
|
@@ -547,6 +547,41 @@ describe('webex-core', () => {
|
|
|
547
547
|
});
|
|
548
548
|
});
|
|
549
549
|
|
|
550
|
+
it('marks a refresh 403 after a 401 with the original catalog status', () => {
|
|
551
|
+
webex.config.credentials.refreshCallback = sinon.stub();
|
|
552
|
+
webex.credentials.supertoken = new Token(
|
|
553
|
+
{
|
|
554
|
+
access_token: 'ST1',
|
|
555
|
+
refresh_token: 'RT1',
|
|
556
|
+
},
|
|
557
|
+
{parent: webex}
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
const refreshError = new Error('forbidden');
|
|
561
|
+
|
|
562
|
+
refreshError.statusCode = 403;
|
|
563
|
+
sinon.stub(webex.credentials, 'refresh').rejects(refreshError);
|
|
564
|
+
|
|
565
|
+
const err = new WebexHttpError.Unauthorized({
|
|
566
|
+
statusCode: 401,
|
|
567
|
+
options: {
|
|
568
|
+
headers: {
|
|
569
|
+
trackingid: 'blarg',
|
|
570
|
+
},
|
|
571
|
+
uri: `${config.services.discovery.hydra}/ping`,
|
|
572
|
+
},
|
|
573
|
+
body: {
|
|
574
|
+
error: 'fake error',
|
|
575
|
+
},
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
return assert.isRejected(interceptor.onResponseError(err.options, err)).then((err2) => {
|
|
579
|
+
assert.equal(err2, refreshError);
|
|
580
|
+
assert.equal(err2.statusCode, 403);
|
|
581
|
+
assert.equal(err2.catalogAuthStatus, 401);
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
|
|
550
585
|
it('does not refresh if shouldRefreshAccessToken was false', () => {
|
|
551
586
|
webex.config.credentials.refreshCallback = sinon.stub().returns(
|
|
552
587
|
Promise.resolve({
|
|
@@ -152,7 +152,41 @@ describe('webex-core', () => {
|
|
|
152
152
|
it('should return a rejected promise', () => {
|
|
153
153
|
const promise = interceptor.onRequest(options);
|
|
154
154
|
|
|
155
|
-
assert.isRejected(
|
|
155
|
+
return assert.isRejected(
|
|
156
|
+
promise,
|
|
157
|
+
Error,
|
|
158
|
+
"service-interceptor: 'example' is not a known service"
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('when the service lookup failed because the token was rejected', () => {
|
|
164
|
+
beforeEach(() => {
|
|
165
|
+
const authError = new Error('invalid_access_token');
|
|
166
|
+
|
|
167
|
+
authError.reason = 'invalid_access_token';
|
|
168
|
+
waitForService.rejects(authError);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('should reject with invalid_access_token', () => {
|
|
172
|
+
const promise = interceptor.onRequest(options);
|
|
173
|
+
|
|
174
|
+
return assert.isRejected(promise, Error, 'invalid_access_token');
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('when the service lookup failed because access was denied', () => {
|
|
179
|
+
beforeEach(() => {
|
|
180
|
+
const authError = new Error('access_denied');
|
|
181
|
+
|
|
182
|
+
authError.reason = 'access_denied';
|
|
183
|
+
waitForService.rejects(authError);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('should reject with access_denied', () => {
|
|
187
|
+
const promise = interceptor.onRequest(options);
|
|
188
|
+
|
|
189
|
+
return assert.isRejected(promise, Error, 'access_denied');
|
|
156
190
|
});
|
|
157
191
|
});
|
|
158
192
|
});
|