@webex/common 3.12.0-next.2 → 3.12.0-next.3
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/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/oauth-state.js +35 -0
- package/dist/oauth-state.js.map +1 -0
- package/package.json +5 -5
- package/src/index.js +1 -0
- package/src/oauth-state.js +25 -0
- package/test/unit/spec/oauth-state.js +69 -0
package/dist/index.js
CHANGED
|
@@ -104,6 +104,12 @@ _Object$defineProperty(exports, "createEventEnvelope", {
|
|
|
104
104
|
return _eventEnvelope.createEventEnvelope;
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
|
+
_Object$defineProperty(exports, "decodeState", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function get() {
|
|
110
|
+
return _oauthState.decodeState;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
107
113
|
_Object$defineProperty(exports, "deconstructHydraId", {
|
|
108
114
|
enumerable: true,
|
|
109
115
|
get: function get() {
|
|
@@ -122,6 +128,12 @@ _Object$defineProperty(exports, "deviceType", {
|
|
|
122
128
|
return _constants.deviceType;
|
|
123
129
|
}
|
|
124
130
|
});
|
|
131
|
+
_Object$defineProperty(exports, "encodeState", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function get() {
|
|
134
|
+
return _oauthState.encodeState;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
125
137
|
_Object$defineProperty(exports, "ensureMyIdIsAvailable", {
|
|
126
138
|
enumerable: true,
|
|
127
139
|
get: function get() {
|
|
@@ -239,6 +251,7 @@ var _makeStateDatatype = _interopRequireDefault(require("./make-state-datatype")
|
|
|
239
251
|
var _templateContainer = _interopRequireDefault(require("./template-container"));
|
|
240
252
|
var _oneFlight = _interopRequireDefault(require("./one-flight"));
|
|
241
253
|
var _patterns = _interopRequireDefault(require("./patterns"));
|
|
254
|
+
var _oauthState = require("./oauth-state");
|
|
242
255
|
var _events = require("./events");
|
|
243
256
|
var _eventEnvelope = require("./event-envelope");
|
|
244
257
|
var _resolveWith = _interopRequireDefault(require("./resolve-with"));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_base","_interopRequireDefault","require","_isBuffer","_cappedDebounce","_checkRequired","_defer","_makeStateDatatype","_templateContainer","_oneFlight","_patterns","_events","_eventEnvelope","_resolveWith","_retry","_tap","_whileInFlight","_exception","_deprecated","_inBrowser","_constants","_browserDetection","_interopRequireWildcard","_uuidUtils","e","t","_WeakMap","r","n","__esModule","o","i","f","__proto__","default","_typeof","has","get","set","_t","hasOwnProperty","call","_Object$defineProperty","_Object$getOwnPropertyDescriptor"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport {default as base64} from './base64';\nexport {default as isBuffer} from './isBuffer';\nexport {default as cappedDebounce} from './capped-debounce';\nexport {default as checkRequired} from './check-required';\nexport {default as Defer} from './defer';\nexport {default as makeStateDataType} from './make-state-datatype';\nexport {default as make} from './template-container';\nexport {default as oneFlight} from './one-flight';\nexport {default as patterns} from './patterns';\n\nexport {proxyEvents, transferEvents} from './events';\nexport {createEventEnvelope, ensureMyIdIsAvailable} from './event-envelope';\nexport {default as resolveWith} from './resolve-with';\nexport {default as retry} from './retry';\nexport {default as tap} from './tap';\nexport {default as whileInFlight} from './while-in-flight';\nexport {default as Exception} from './exception';\nexport {default as deprecated} from './deprecated';\nexport {default as inBrowser} from './in-browser';\nexport {\n deviceType,\n hydraTypes,\n SDK_EVENT,\n INTERNAL_US_CLUSTER_NAME,\n INTERNAL_US_INTEGRATION_CLUSTER_NAME,\n} from './constants';\n\nexport {default as BrowserDetection, getBrowserSerial} from './browser-detection';\nexport {\n buildHydraMembershipId,\n buildHydraMessageId,\n buildHydraOrgId,\n buildHydraPersonId,\n buildHydraRoomId,\n getHydraRoomType,\n getHydraClusterString,\n getHydraFiles,\n constructHydraId,\n deconstructHydraId,\n} from './uuid-utils';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_base","_interopRequireDefault","require","_isBuffer","_cappedDebounce","_checkRequired","_defer","_makeStateDatatype","_templateContainer","_oneFlight","_patterns","_oauthState","_events","_eventEnvelope","_resolveWith","_retry","_tap","_whileInFlight","_exception","_deprecated","_inBrowser","_constants","_browserDetection","_interopRequireWildcard","_uuidUtils","e","t","_WeakMap","r","n","__esModule","o","i","f","__proto__","default","_typeof","has","get","set","_t","hasOwnProperty","call","_Object$defineProperty","_Object$getOwnPropertyDescriptor"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nexport {default as base64} from './base64';\nexport {default as isBuffer} from './isBuffer';\nexport {default as cappedDebounce} from './capped-debounce';\nexport {default as checkRequired} from './check-required';\nexport {default as Defer} from './defer';\nexport {default as makeStateDataType} from './make-state-datatype';\nexport {default as make} from './template-container';\nexport {default as oneFlight} from './one-flight';\nexport {default as patterns} from './patterns';\n\nexport {encodeState, decodeState} from './oauth-state';\nexport {proxyEvents, transferEvents} from './events';\nexport {createEventEnvelope, ensureMyIdIsAvailable} from './event-envelope';\nexport {default as resolveWith} from './resolve-with';\nexport {default as retry} from './retry';\nexport {default as tap} from './tap';\nexport {default as whileInFlight} from './while-in-flight';\nexport {default as Exception} from './exception';\nexport {default as deprecated} from './deprecated';\nexport {default as inBrowser} from './in-browser';\nexport {\n deviceType,\n hydraTypes,\n SDK_EVENT,\n INTERNAL_US_CLUSTER_NAME,\n INTERNAL_US_INTEGRATION_CLUSTER_NAME,\n} from './constants';\n\nexport {default as BrowserDetection, getBrowserSerial} from './browser-detection';\nexport {\n buildHydraMembershipId,\n buildHydraMessageId,\n buildHydraOrgId,\n buildHydraPersonId,\n buildHydraRoomId,\n getHydraRoomType,\n getHydraClusterString,\n getHydraFiles,\n constructHydraId,\n deconstructHydraId,\n} from './uuid-utils';\n"],"mappings":";;;;;;;;;;;;;;;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;AAWsB,SAAAqB,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,QAAA,MAAAC,CAAA,OAAAD,QAAA,IAAAE,CAAA,OAAAF,QAAA,YAAAJ,uBAAA,YAAAA,wBAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,gBAAAW,OAAA,CAAAX,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAM,GAAA,CAAAZ,CAAA,UAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,GAAAM,CAAA,CAAAQ,GAAA,CAAAd,CAAA,EAAAQ,CAAA,cAAAO,EAAA,IAAAf,CAAA,gBAAAe,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAe,EAAA,OAAAR,CAAA,IAAAD,CAAA,GAAAY,sBAAA,KAAAC,gCAAA,CAAAnB,CAAA,EAAAe,EAAA,OAAAR,CAAA,CAAAM,GAAA,IAAAN,CAAA,CAAAO,GAAA,IAAAR,CAAA,CAAAE,CAAA,EAAAO,EAAA,EAAAR,CAAA,IAAAC,CAAA,CAAAO,EAAA,IAAAf,CAAA,CAAAe,EAAA,WAAAP,CAAA,KAAAR,CAAA,EAAAC,CAAA","ignoreList":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
5
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.decodeState = decodeState;
|
|
9
|
+
exports.encodeState = encodeState;
|
|
10
|
+
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify"));
|
|
11
|
+
var _base = require("./base64");
|
|
12
|
+
/*!
|
|
13
|
+
* Copyright (c) 2015-2024 Cisco Systems, Inc. See LICENSE file.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Encodes a state object for transport through OAuth redirect query strings.
|
|
18
|
+
* Serializes as JSON and encodes as base64url. Pairs with `decodeState`.
|
|
19
|
+
* @param {Object} state
|
|
20
|
+
* @returns {string}
|
|
21
|
+
*/
|
|
22
|
+
function encodeState(state) {
|
|
23
|
+
return (0, _base.toBase64Url)((0, _stringify.default)(state));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Decodes a base64url-encoded state string back into the original object.
|
|
28
|
+
* Pairs with `encodeState`. Throws if the input is not valid base64url JSON.
|
|
29
|
+
* @param {string} encoded
|
|
30
|
+
* @returns {Object}
|
|
31
|
+
*/
|
|
32
|
+
function decodeState(encoded) {
|
|
33
|
+
return JSON.parse((0, _base.fromBase64url)(encoded));
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=oauth-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_base","require","encodeState","state","toBase64Url","_stringify","default","decodeState","encoded","JSON","parse","fromBase64url"],"sources":["oauth-state.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2024 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {fromBase64url, toBase64Url} from './base64';\n\n/**\n * Encodes a state object for transport through OAuth redirect query strings.\n * Serializes as JSON and encodes as base64url. Pairs with `decodeState`.\n * @param {Object} state\n * @returns {string}\n */\nexport function encodeState(state) {\n return toBase64Url(JSON.stringify(state));\n}\n\n/**\n * Decodes a base64url-encoded state string back into the original object.\n * Pairs with `encodeState`. Throws if the input is not valid base64url JSON.\n * @param {string} encoded\n * @returns {Object}\n */\nexport function decodeState(encoded) {\n return JSON.parse(fromBase64url(encoded));\n}\n"],"mappings":";;;;;;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,WAAWA,CAACC,KAAK,EAAE;EACjC,OAAO,IAAAC,iBAAW,EAAC,IAAAC,UAAA,CAAAC,OAAA,EAAeH,KAAK,CAAC,CAAC;AAC3C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,WAAWA,CAACC,OAAO,EAAE;EACnC,OAAOC,IAAI,CAACC,KAAK,CAAC,IAAAC,mBAAa,EAACH,OAAO,CAAC,CAAC;AAC3C","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"@webex/eslint-config-legacy": "0.0.0",
|
|
30
30
|
"@webex/jest-config-legacy": "0.0.0",
|
|
31
31
|
"@webex/legacy-tools": "0.0.0",
|
|
32
|
-
"@webex/test-helper-chai": "3.12.0-next.
|
|
33
|
-
"@webex/test-helper-mocha": "3.12.0-next.
|
|
34
|
-
"@webex/test-helper-mock-webex": "3.12.0-next.
|
|
35
|
-
"@webex/test-helper-test-users": "3.12.0-next.
|
|
32
|
+
"@webex/test-helper-chai": "3.12.0-next.3",
|
|
33
|
+
"@webex/test-helper-mocha": "3.12.0-next.3",
|
|
34
|
+
"@webex/test-helper-mock-webex": "3.12.0-next.3",
|
|
35
|
+
"@webex/test-helper-test-users": "3.12.0-next.3",
|
|
36
36
|
"ampersand-state": "^5.0.3",
|
|
37
37
|
"eslint": "^8.24.0",
|
|
38
38
|
"prettier": "^2.7.1",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"test:style": "eslint ./src/**/*.*",
|
|
56
56
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
57
57
|
},
|
|
58
|
-
"version": "3.12.0-next.
|
|
58
|
+
"version": "3.12.0-next.3"
|
|
59
59
|
}
|
package/src/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export {default as make} from './template-container';
|
|
|
12
12
|
export {default as oneFlight} from './one-flight';
|
|
13
13
|
export {default as patterns} from './patterns';
|
|
14
14
|
|
|
15
|
+
export {encodeState, decodeState} from './oauth-state';
|
|
15
16
|
export {proxyEvents, transferEvents} from './events';
|
|
16
17
|
export {createEventEnvelope, ensureMyIdIsAvailable} from './event-envelope';
|
|
17
18
|
export {default as resolveWith} from './resolve-with';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2024 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {fromBase64url, toBase64Url} from './base64';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Encodes a state object for transport through OAuth redirect query strings.
|
|
9
|
+
* Serializes as JSON and encodes as base64url. Pairs with `decodeState`.
|
|
10
|
+
* @param {Object} state
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
export function encodeState(state) {
|
|
14
|
+
return toBase64Url(JSON.stringify(state));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Decodes a base64url-encoded state string back into the original object.
|
|
19
|
+
* Pairs with `encodeState`. Throws if the input is not valid base64url JSON.
|
|
20
|
+
* @param {string} encoded
|
|
21
|
+
* @returns {Object}
|
|
22
|
+
*/
|
|
23
|
+
export function decodeState(encoded) {
|
|
24
|
+
return JSON.parse(fromBase64url(encoded));
|
|
25
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2024 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {assert} from '@webex/test-helper-chai';
|
|
6
|
+
import {decodeState, encodeState} from '@webex/common';
|
|
7
|
+
|
|
8
|
+
describe('oauth-state', () => {
|
|
9
|
+
describe('encodeState() / decodeState()', () => {
|
|
10
|
+
it('encodeState produces the expected base64url string', () => {
|
|
11
|
+
const encoded = encodeState({csrf_token: 'abc'});
|
|
12
|
+
|
|
13
|
+
assert.equal(encoded, 'eyJjc3JmX3Rva2VuIjoiYWJjIn0');
|
|
14
|
+
assert.notInclude(encoded, '+');
|
|
15
|
+
assert.notInclude(encoded, '/');
|
|
16
|
+
assert.notInclude(encoded, '=');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('encodeState produces the expected base64url string for an empty object', () => {
|
|
20
|
+
const encoded = encodeState({});
|
|
21
|
+
|
|
22
|
+
assert.equal(encoded, 'e30');
|
|
23
|
+
assert.notInclude(encoded, '+');
|
|
24
|
+
assert.notInclude(encoded, '/');
|
|
25
|
+
assert.notInclude(encoded, '=');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('decodeState parses a known base64url string', () => {
|
|
29
|
+
assert.deepEqual(decodeState('eyJjc3JmX3Rva2VuIjoiYWJjIn0'), {csrf_token: 'abc'});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('decodeState parses an empty-object encoding', () => {
|
|
33
|
+
assert.deepEqual(decodeState('e30'), {});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('round-trips a typical state object', () => {
|
|
37
|
+
const state = {csrf_token: 'abc123', provider: 'google', returnURL: '/app'};
|
|
38
|
+
const encoded = encodeState(state);
|
|
39
|
+
|
|
40
|
+
assert.notInclude(encoded, '+');
|
|
41
|
+
assert.notInclude(encoded, '/');
|
|
42
|
+
assert.notInclude(encoded, '=');
|
|
43
|
+
assert.deepEqual(decodeState(encoded), state);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('round-trips an empty object', () => {
|
|
47
|
+
const encoded = encodeState({});
|
|
48
|
+
|
|
49
|
+
assert.notInclude(encoded, '+');
|
|
50
|
+
assert.notInclude(encoded, '/');
|
|
51
|
+
assert.notInclude(encoded, '=');
|
|
52
|
+
assert.deepEqual(decodeState(encoded), {});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('produces a url-safe encoding (no +, /, or = padding)', () => {
|
|
56
|
+
// Inputs chosen so the resulting bytes would include +, / and padding under
|
|
57
|
+
// standard base64.
|
|
58
|
+
const encoded = encodeState({a: '???>>>'});
|
|
59
|
+
|
|
60
|
+
assert.notInclude(encoded, '+');
|
|
61
|
+
assert.notInclude(encoded, '/');
|
|
62
|
+
assert.notInclude(encoded, '=');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('throws when decoding invalid input', () => {
|
|
66
|
+
assert.throws(() => decodeState('not-valid-base64-json'));
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|