@webex/webex-core 3.0.0-beta.13 → 3.0.0-beta.15
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/config.js.map +1 -1
- package/dist/credentials-config.js +44 -44
- package/dist/credentials-config.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interceptors/auth.js.map +1 -1
- package/dist/interceptors/default-options.js.map +1 -1
- package/dist/interceptors/embargo.js.map +1 -1
- package/dist/interceptors/payload-transformer.js.map +1 -1
- package/dist/interceptors/rate-limit.js +4 -4
- package/dist/interceptors/rate-limit.js.map +1 -1
- package/dist/interceptors/redirect.js.map +1 -1
- package/dist/interceptors/request-event.js.map +1 -1
- package/dist/interceptors/request-logger.js.map +1 -1
- package/dist/interceptors/response-logger.js.map +1 -1
- package/dist/interceptors/user-agent.js.map +1 -1
- package/dist/interceptors/webex-user-agent.js.map +1 -1
- package/dist/lib/batcher.js +1 -1
- package/dist/lib/batcher.js.map +1 -1
- package/dist/lib/credentials/credentials.js +21 -6
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/grant-errors.js.map +1 -1
- package/dist/lib/credentials/index.js.map +1 -1
- package/dist/lib/credentials/scope.js.map +1 -1
- package/dist/lib/credentials/token-collection.js.map +1 -1
- package/dist/lib/credentials/token.js +19 -5
- package/dist/lib/credentials/token.js.map +1 -1
- package/dist/lib/page.js +2 -0
- package/dist/lib/page.js.map +1 -1
- package/dist/lib/services/constants.js.map +1 -1
- package/dist/lib/services/index.js.map +1 -1
- package/dist/lib/services/interceptors/server-error.js +2 -2
- package/dist/lib/services/interceptors/server-error.js.map +1 -1
- package/dist/lib/services/interceptors/service.js +1 -1
- package/dist/lib/services/interceptors/service.js.map +1 -1
- package/dist/lib/services/metrics.js.map +1 -1
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/service-fed-ramp.js.map +1 -1
- package/dist/lib/services/service-host.js +6 -6
- package/dist/lib/services/service-host.js.map +1 -1
- package/dist/lib/services/service-registry.js.map +1 -1
- package/dist/lib/services/service-state.js.map +1 -1
- package/dist/lib/services/service-url.js.map +1 -1
- package/dist/lib/services/services.js +9 -7
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/stateless-webex-plugin.js.map +1 -1
- package/dist/lib/storage/decorators.js.map +1 -1
- package/dist/lib/storage/index.js +2 -2
- package/dist/lib/storage/index.js.map +1 -1
- package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
- package/dist/lib/storage/make-webex-store.js.map +1 -1
- package/dist/lib/storage/memory-store-adapter.js.map +1 -1
- package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-http-error.js.map +1 -1
- package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
- package/dist/lib/webex-plugin.js.map +1 -1
- package/dist/plugins/logger.js +1 -1
- package/dist/plugins/logger.js.map +1 -1
- package/dist/webex-core.js +2 -2
- package/dist/webex-core.js.map +1 -1
- package/dist/webex-internal-core.js.map +1 -1
- package/package.json +14 -14
- package/src/config.js +9 -11
- package/src/credentials-config.js +110 -72
- package/src/index.js +4 -14
- package/src/interceptors/auth.js +36 -37
- package/src/interceptors/default-options.js +0 -1
- package/src/interceptors/embargo.js +1 -1
- package/src/interceptors/payload-transformer.js +1 -2
- package/src/interceptors/rate-limit.js +8 -5
- package/src/interceptors/redirect.js +14 -8
- package/src/interceptors/request-event.js +4 -8
- package/src/interceptors/request-logger.js +8 -5
- package/src/interceptors/response-logger.js +11 -8
- package/src/interceptors/user-agent.js +1 -2
- package/src/interceptors/webex-user-agent.js +3 -9
- package/src/lib/batcher.js +70 -69
- package/src/lib/credentials/credentials.js +112 -122
- package/src/lib/credentials/grant-errors.js +6 -7
- package/src/lib/credentials/index.js +1 -4
- package/src/lib/credentials/scope.js +1 -4
- package/src/lib/credentials/token-collection.js +1 -1
- package/src/lib/credentials/token.js +86 -80
- package/src/lib/page.js +10 -11
- package/src/lib/services/constants.js +3 -13
- package/src/lib/services/index.js +2 -2
- package/src/lib/services/interceptors/server-error.js +12 -7
- package/src/lib/services/interceptors/service.js +6 -5
- package/src/lib/services/metrics.js +1 -1
- package/src/lib/services/service-catalog.js +110 -100
- package/src/lib/services/service-fed-ramp.js +1 -2
- package/src/lib/services/service-host.js +10 -17
- package/src/lib/services/service-registry.js +69 -96
- package/src/lib/services/service-state.js +4 -6
- package/src/lib/services/service-url.js +24 -23
- package/src/lib/services/services.js +260 -251
- package/src/lib/stateless-webex-plugin.js +4 -2
- package/src/lib/storage/decorators.js +68 -66
- package/src/lib/storage/index.js +4 -6
- package/src/lib/storage/make-webex-plugin-store.js +34 -21
- package/src/lib/storage/make-webex-store.js +6 -7
- package/src/lib/storage/memory-store-adapter.js +3 -3
- package/src/lib/webex-core-plugin-mixin.js +10 -7
- package/src/lib/webex-http-error.js +7 -8
- package/src/lib/webex-internal-core-plugin-mixin.js +9 -6
- package/src/lib/webex-plugin.js +41 -34
- package/src/plugins/logger.js +8 -3
- package/src/webex-core.js +185 -116
- package/src/webex-internal-core.js +15 -9
- package/test/integration/spec/credentials/credentials.js +26 -30
- package/test/integration/spec/credentials/token.js +36 -33
- package/test/integration/spec/services/service-catalog.js +177 -156
- package/test/integration/spec/services/services.js +313 -304
- package/test/integration/spec/webex-core.js +98 -86
- package/test/unit/spec/_setup.js +26 -18
- package/test/unit/spec/credentials/credentials.js +189 -154
- package/test/unit/spec/credentials/token.js +94 -76
- package/test/unit/spec/interceptors/auth.js +291 -243
- package/test/unit/spec/interceptors/default-options.js +36 -24
- package/test/unit/spec/interceptors/embargo.js +32 -27
- package/test/unit/spec/interceptors/network-timing.js +2 -2
- package/test/unit/spec/interceptors/payload-transformer.js +61 -52
- package/test/unit/spec/interceptors/rate-limit.js +104 -75
- package/test/unit/spec/interceptors/redirect.js +22 -20
- package/test/unit/spec/interceptors/request-timing.js +18 -22
- package/test/unit/spec/interceptors/user-agent.js +28 -16
- package/test/unit/spec/interceptors/webex-tracking-id.js +14 -8
- package/test/unit/spec/interceptors/webex-user-agent.js +83 -37
- package/test/unit/spec/lib/batcher.js +36 -32
- package/test/unit/spec/lib/page.js +36 -32
- package/test/unit/spec/lib/webex-plugin.js +1 -1
- package/test/unit/spec/services/interceptors/server-error.js +67 -90
- package/test/unit/spec/services/interceptors/service.js +17 -28
- package/test/unit/spec/services/service-catalog.js +19 -27
- package/test/unit/spec/services/service-host.js +29 -26
- package/test/unit/spec/services/service-registry.js +128 -170
- package/test/unit/spec/services/service-state.js +13 -22
- package/test/unit/spec/services/service-url.js +24 -43
- package/test/unit/spec/services/services.js +85 -41
- package/test/unit/spec/storage/persist.js +6 -9
- package/test/unit/spec/storage/wait-for-value.js +22 -21
- package/test/unit/spec/webex-core.js +78 -57
- package/test/unit/spec/webex-internal-core.js +56 -31
|
@@ -4,7 +4,6 @@ import AmpState from 'ampersand-state';
|
|
|
4
4
|
// URL properties from them for the various CI services. The URL's
|
|
5
5
|
// will be updated when the CI changes.
|
|
6
6
|
const CredentialsConfig = AmpState.extend({
|
|
7
|
-
|
|
8
7
|
// we need to allow extra props for dynamic props like jwtRefreshCallback
|
|
9
8
|
extraProperties: 'allow',
|
|
10
9
|
|
|
@@ -13,24 +12,36 @@ const CredentialsConfig = AmpState.extend({
|
|
|
13
12
|
* The idbroker base host name
|
|
14
13
|
* @returns {object}
|
|
15
14
|
*/
|
|
16
|
-
idbroker: [
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
idbroker: [
|
|
16
|
+
'object',
|
|
17
|
+
false,
|
|
18
|
+
() => ({
|
|
19
|
+
url: process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com',
|
|
20
|
+
}),
|
|
21
|
+
],
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
24
|
* The identity base host name
|
|
22
25
|
* @returns {object}
|
|
23
26
|
*/
|
|
24
|
-
identity: [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
identity: [
|
|
28
|
+
'object',
|
|
29
|
+
false,
|
|
30
|
+
() => ({
|
|
31
|
+
url: process.env.IDENTITY_BASE_URL || 'https://identity.webex.com',
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
27
34
|
|
|
28
35
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
authorizationString: [
|
|
36
|
+
* This is the authorization url displayed on the
|
|
37
|
+
* {@link developer portal|https://developer.webex.com}
|
|
38
|
+
* @type {string}
|
|
39
|
+
*/
|
|
40
|
+
authorizationString: [
|
|
41
|
+
'string',
|
|
42
|
+
false,
|
|
43
|
+
process.env.WEBEX_AUTHORIZATION_STRING || process.env.AUTHORIZATION_STRING,
|
|
44
|
+
],
|
|
34
45
|
|
|
35
46
|
/**
|
|
36
47
|
* Authorization URL which prompts for user's password. Inferred from
|
|
@@ -43,132 +54,159 @@ const CredentialsConfig = AmpState.extend({
|
|
|
43
54
|
'string',
|
|
44
55
|
false,
|
|
45
56
|
process.env.WEBEX_AUTHORIZE_URL ||
|
|
46
|
-
|
|
57
|
+
`${process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'}/idb/oauth2/v1/authorize`,
|
|
47
58
|
],
|
|
48
59
|
|
|
49
60
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
client_id: [
|
|
61
|
+
* {@see https://tools.ietf.org/html/rfc6749#section-4.1.4}
|
|
62
|
+
* @type {string}
|
|
63
|
+
*/
|
|
64
|
+
client_id: [
|
|
65
|
+
'string',
|
|
66
|
+
false,
|
|
67
|
+
process.env.WEBEX_CLIENT_ID || process.env.COMMON_IDENTITY_CLIENT_ID || process.env.CLIENT_ID,
|
|
68
|
+
],
|
|
54
69
|
|
|
55
70
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
client_secret: [
|
|
71
|
+
* {@see https://tools.ietf.org/html/rfc6749#section-4.1.4}
|
|
72
|
+
* @type {string}
|
|
73
|
+
*/
|
|
74
|
+
client_secret: [
|
|
75
|
+
'string',
|
|
76
|
+
false,
|
|
77
|
+
process.env.WEBEX_CLIENT_SECRET ||
|
|
78
|
+
process.env.COMMON_IDENTITY_CLIENT_SECRET ||
|
|
79
|
+
process.env.CLIENT_SECRET,
|
|
80
|
+
],
|
|
60
81
|
|
|
61
82
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
redirect_uri: [
|
|
83
|
+
* {@see https://tools.ietf.org/html/rfc6749#section-4.1.4}
|
|
84
|
+
* @type {string}
|
|
85
|
+
*/
|
|
86
|
+
redirect_uri: [
|
|
87
|
+
'string',
|
|
88
|
+
false,
|
|
89
|
+
process.env.WEBEX_REDIRECT_URI ||
|
|
90
|
+
process.env.COMMON_IDENTITY_REDIRECT_URI ||
|
|
91
|
+
process.env.REDIRECT_URI,
|
|
92
|
+
],
|
|
66
93
|
|
|
67
94
|
/**
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
scope: [
|
|
95
|
+
* {@see https://tools.ietf.org/html/rfc6749#section-4.1.4}
|
|
96
|
+
* @type {string}
|
|
97
|
+
*/
|
|
98
|
+
scope: [
|
|
99
|
+
'string',
|
|
100
|
+
false,
|
|
101
|
+
process.env.WEBEX_SCOPE ||
|
|
102
|
+
process.env.WEBEX_SCOPES ||
|
|
103
|
+
process.env.COMMON_IDENTITY_SCOPE ||
|
|
104
|
+
process.env.SCOPE,
|
|
105
|
+
],
|
|
72
106
|
|
|
73
107
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
cisService: ['string', false, 'webex']
|
|
108
|
+
* Controls the UI of the CI login page.
|
|
109
|
+
* @private
|
|
110
|
+
* @type {string}
|
|
111
|
+
*/
|
|
112
|
+
cisService: ['string', false, 'webex'],
|
|
79
113
|
},
|
|
80
114
|
|
|
81
115
|
derived: {
|
|
82
116
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
* User activation URL
|
|
118
|
+
* {@link config.credentials.activationUrl}
|
|
119
|
+
* @type {string}
|
|
120
|
+
*/
|
|
87
121
|
activationUrl: {
|
|
88
122
|
deps: ['idbroker.url'],
|
|
89
123
|
fn() {
|
|
90
|
-
return `${
|
|
124
|
+
return `${
|
|
125
|
+
this.idbroker.url || 'https://idbroker.webex.com'
|
|
126
|
+
}/idb/token/v1/actions/UserActivation/invoke`;
|
|
91
127
|
},
|
|
92
|
-
cache: false
|
|
128
|
+
cache: false,
|
|
93
129
|
},
|
|
94
130
|
|
|
95
131
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
132
|
+
* Generate OTP URL
|
|
133
|
+
* {@link config.credentials.generateOtpUrl}
|
|
134
|
+
* @type {string}
|
|
135
|
+
*/
|
|
100
136
|
generateOtpUrl: {
|
|
101
137
|
deps: ['idbroker.url'],
|
|
102
138
|
fn() {
|
|
103
|
-
return `${
|
|
139
|
+
return `${
|
|
140
|
+
this.idbroker.url || 'https://idbroker.webex.com'
|
|
141
|
+
}/idb/token/v1/actions/UserOTP/Generate/invoke`;
|
|
104
142
|
},
|
|
105
|
-
cache: false
|
|
143
|
+
cache: false,
|
|
106
144
|
},
|
|
107
145
|
|
|
108
146
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
147
|
+
* Validate OTP URL
|
|
148
|
+
* {@link config.credentials.validateOtpUrl}
|
|
149
|
+
* @type {string}
|
|
150
|
+
*/
|
|
113
151
|
validateOtpUrl: {
|
|
114
152
|
deps: ['idbroker.url'],
|
|
115
153
|
fn() {
|
|
116
|
-
return `${
|
|
154
|
+
return `${
|
|
155
|
+
this.idbroker.url || 'https://idbroker.webex.com'
|
|
156
|
+
}/idb/token/v1/actions/UserOTP/Validate/invoke`;
|
|
117
157
|
},
|
|
118
|
-
cache: false
|
|
158
|
+
cache: false,
|
|
119
159
|
},
|
|
120
160
|
|
|
121
161
|
// TODO does hydra also have an access_token endpoint?
|
|
122
162
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
163
|
+
* Token URL used for token refresh and auth code exchange
|
|
164
|
+
* @type {string}
|
|
165
|
+
*/
|
|
126
166
|
tokenUrl: {
|
|
127
167
|
deps: ['idbroker.url'],
|
|
128
168
|
fn() {
|
|
129
169
|
return process.env.TOKEN_URL || `${this.idbroker.url}/idb/oauth2/v1/access_token`;
|
|
130
170
|
},
|
|
131
|
-
cache: false
|
|
171
|
+
cache: false,
|
|
132
172
|
},
|
|
133
173
|
|
|
134
174
|
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
175
|
+
* URL to revoke token
|
|
176
|
+
* @type {string}
|
|
177
|
+
*/
|
|
138
178
|
revokeUrl: {
|
|
139
179
|
deps: ['idbroker.url'],
|
|
140
180
|
fn() {
|
|
141
181
|
return process.env.REVOKE_URL || `${this.idbroker.url}/idb/oauth2/v1/revoke`;
|
|
142
182
|
},
|
|
143
|
-
cache: false
|
|
183
|
+
cache: false,
|
|
144
184
|
},
|
|
145
185
|
|
|
146
186
|
/**
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
187
|
+
* URL to load when the app logs out
|
|
188
|
+
* @type {string}
|
|
189
|
+
*/
|
|
150
190
|
logoutUrl: {
|
|
151
191
|
deps: ['idbroker.url'],
|
|
152
192
|
fn() {
|
|
153
193
|
return `${this.idbroker.url}/idb/oauth2/v1/logout`;
|
|
154
194
|
},
|
|
155
|
-
cache: false
|
|
195
|
+
cache: false,
|
|
156
196
|
},
|
|
157
197
|
|
|
158
198
|
/**
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
199
|
+
* Set password URL
|
|
200
|
+
* @type {string}
|
|
201
|
+
*/
|
|
162
202
|
setPasswordUrl: {
|
|
163
203
|
deps: ['identity.url'],
|
|
164
204
|
fn() {
|
|
165
205
|
return `${this.identity.url || 'https://identity.webex.com'}/identity/scim/v1/Users`;
|
|
166
206
|
},
|
|
167
|
-
cache: false
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
207
|
+
cache: false,
|
|
208
|
+
},
|
|
209
|
+
},
|
|
172
210
|
});
|
|
173
211
|
|
|
174
212
|
export default CredentialsConfig;
|
package/src/index.js
CHANGED
|
@@ -13,13 +13,7 @@ import './plugins/logger';
|
|
|
13
13
|
import './lib/credentials';
|
|
14
14
|
import './lib/services';
|
|
15
15
|
|
|
16
|
-
export {
|
|
17
|
-
Credentials,
|
|
18
|
-
filterScope,
|
|
19
|
-
grantErrors,
|
|
20
|
-
sortScope,
|
|
21
|
-
Token
|
|
22
|
-
} from './lib/credentials';
|
|
16
|
+
export {Credentials, filterScope, grantErrors, sortScope, Token} from './lib/credentials';
|
|
23
17
|
|
|
24
18
|
export {
|
|
25
19
|
constants as serviceConstants,
|
|
@@ -30,7 +24,7 @@ export {
|
|
|
30
24
|
ServerErrorInterceptor,
|
|
31
25
|
Services,
|
|
32
26
|
ServiceHost,
|
|
33
|
-
ServiceUrl
|
|
27
|
+
ServiceUrl,
|
|
34
28
|
} from './lib/services';
|
|
35
29
|
|
|
36
30
|
export {
|
|
@@ -40,14 +34,10 @@ export {
|
|
|
40
34
|
NotFoundError,
|
|
41
35
|
persist,
|
|
42
36
|
StorageError,
|
|
43
|
-
waitForValue
|
|
37
|
+
waitForValue,
|
|
44
38
|
} from './lib/storage';
|
|
45
39
|
|
|
46
|
-
export {
|
|
47
|
-
default,
|
|
48
|
-
registerPlugin,
|
|
49
|
-
registerInternalPlugin
|
|
50
|
-
} from './webex-core';
|
|
40
|
+
export {default, registerPlugin, registerInternalPlugin} from './webex-core';
|
|
51
41
|
|
|
52
42
|
export {default as WebexHttpError} from './lib/webex-http-error';
|
|
53
43
|
export {default as StatelessWebexPlugin} from './lib/stateless-webex-plugin';
|
package/src/interceptors/auth.js
CHANGED
|
@@ -34,19 +34,17 @@ export default class AuthInterceptor extends Interceptor {
|
|
|
34
34
|
return Promise.resolve(options);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
return this.requiresCredentials(options)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
37
|
+
return this.requiresCredentials(options).then((requires) => {
|
|
38
|
+
if (!requires) {
|
|
39
|
+
return options;
|
|
40
|
+
}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
options.headers.authorization = token.toString();
|
|
42
|
+
return this.webex.credentials.getUserToken().then((token) => {
|
|
43
|
+
options.headers.authorization = token.toString();
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
});
|
|
45
|
+
return options;
|
|
49
46
|
});
|
|
47
|
+
});
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
/**
|
|
@@ -77,26 +75,26 @@ export default class AuthInterceptor extends Interceptor {
|
|
|
77
75
|
|
|
78
76
|
// Unique validation for the u2c service.
|
|
79
77
|
if ((service && service === 'u2c') || (name && name === 'u2c')) {
|
|
80
|
-
if (
|
|
81
|
-
(resource && resource.includes('limited')) ||
|
|
82
|
-
(uri && uri.includes('limited'))
|
|
83
|
-
) {
|
|
78
|
+
if ((resource && resource.includes('limited')) || (uri && uri.includes('limited'))) {
|
|
84
79
|
return Promise.resolve(false);
|
|
85
80
|
}
|
|
86
81
|
|
|
87
82
|
return Promise.resolve(true);
|
|
88
83
|
}
|
|
89
84
|
|
|
90
|
-
|
|
91
85
|
// Validate that the allowed domains can be utilized.
|
|
92
|
-
if (
|
|
86
|
+
if (
|
|
87
|
+
services.validateDomains &&
|
|
93
88
|
services.hasAllowedDomains() &&
|
|
94
|
-
|
|
89
|
+
uri &&
|
|
90
|
+
services.isAllowedDomainUrl(uri)
|
|
91
|
+
) {
|
|
95
92
|
return Promise.resolve(true);
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
// Perform an additional validation in case the service does not exist yet.
|
|
99
|
-
return services
|
|
96
|
+
return services
|
|
97
|
+
.waitForService({name: service, url: uri})
|
|
100
98
|
.then((detectedUrl) => {
|
|
101
99
|
// Validate that the url exists in the catalog.
|
|
102
100
|
if (services.getServiceFromUrl(detectedUrl)) {
|
|
@@ -123,23 +121,21 @@ export default class AuthInterceptor extends Interceptor {
|
|
|
123
121
|
* @returns {Object}
|
|
124
122
|
*/
|
|
125
123
|
onResponseError(options, reason) {
|
|
126
|
-
return this.shouldAttemptReauth(reason, options)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
Reflect.deleteProperty(reason.options.headers, 'authorization');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (this.webex.credentials.canRefresh) {
|
|
136
|
-
return this.webex.credentials.refresh()
|
|
137
|
-
.then(() => this.replay(options));
|
|
138
|
-
}
|
|
124
|
+
return this.shouldAttemptReauth(reason, options).then((shouldAttemptReauth) => {
|
|
125
|
+
if (shouldAttemptReauth) {
|
|
126
|
+
this.webex.logger.info('auth: received 401, attempting to reauthenticate');
|
|
127
|
+
|
|
128
|
+
if (reason.options.headers) {
|
|
129
|
+
Reflect.deleteProperty(reason.options.headers, 'authorization');
|
|
139
130
|
}
|
|
140
131
|
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
if (this.webex.credentials.canRefresh) {
|
|
133
|
+
return this.webex.credentials.refresh().then(() => this.replay(options));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return Promise.reject(reason);
|
|
138
|
+
});
|
|
143
139
|
}
|
|
144
140
|
|
|
145
141
|
/**
|
|
@@ -150,15 +146,18 @@ export default class AuthInterceptor extends Interceptor {
|
|
|
150
146
|
replay(options) {
|
|
151
147
|
if (options.replayCount) {
|
|
152
148
|
options.replayCount += 1;
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
149
|
+
} else {
|
|
155
150
|
options.replayCount = 1;
|
|
156
151
|
}
|
|
157
152
|
|
|
158
153
|
if (options.replayCount > this.webex.config.maxAuthenticationReplays) {
|
|
159
|
-
this.webex.logger.error(
|
|
154
|
+
this.webex.logger.error(
|
|
155
|
+
`auth: failed after ${this.webex.config.maxAuthenticationReplays} replay attempts`
|
|
156
|
+
);
|
|
160
157
|
|
|
161
|
-
return Promise.reject(
|
|
158
|
+
return Promise.reject(
|
|
159
|
+
new Error(`Failed after ${this.webex.config.maxAuthenticationReplays} replay attempts`)
|
|
160
|
+
);
|
|
162
161
|
}
|
|
163
162
|
|
|
164
163
|
this.webex.logger.info(`auth: replaying request ${options.replayCount} time`);
|
|
@@ -27,7 +27,7 @@ export default class EmbargoInterceptor extends Interceptor {
|
|
|
27
27
|
const {device} = this.webex.internal;
|
|
28
28
|
const loggerMessage = [
|
|
29
29
|
'Received `HTTP 451 Unavailable For Legal Reasons`, ',
|
|
30
|
-
'discarding credentials and device registration'
|
|
30
|
+
'discarding credentials and device registration',
|
|
31
31
|
].join('');
|
|
32
32
|
|
|
33
33
|
if (device) {
|
|
@@ -50,7 +50,6 @@ export default class PayloadTransformerInterceptor extends Interceptor {
|
|
|
50
50
|
* @returns {Object}
|
|
51
51
|
*/
|
|
52
52
|
onResponseError(options, reason) {
|
|
53
|
-
return this.webex.transform('inbound', reason)
|
|
54
|
-
.then((r) => Promise.reject(r || reason));
|
|
53
|
+
return this.webex.transform('inbound', reason).then((r) => Promise.reject(r || reason));
|
|
55
54
|
}
|
|
56
55
|
}
|
|
@@ -23,10 +23,10 @@ export default class RateLimitInterceptor extends Interceptor {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
* constructor
|
|
27
|
+
* @param {mixed} args
|
|
28
|
+
* @returns {Exception}
|
|
29
|
+
*/
|
|
30
30
|
constructor(...args) {
|
|
31
31
|
super(...args);
|
|
32
32
|
rateLimitExpiryTime.set(this, new Map());
|
|
@@ -52,7 +52,10 @@ export default class RateLimitInterceptor extends Interceptor {
|
|
|
52
52
|
* @returns {Object}
|
|
53
53
|
*/
|
|
54
54
|
onResponseError(options, reason) {
|
|
55
|
-
if (
|
|
55
|
+
if (
|
|
56
|
+
reason.statusCode === 429 &&
|
|
57
|
+
(options.uri.includes('idbroker') || options.uri.includes('identity'))
|
|
58
|
+
) {
|
|
56
59
|
// set the retry after in the map, setting to milliseconds
|
|
57
60
|
this.setRateLimitExpiry(options.uri, this.extractRetryAfterTime(options));
|
|
58
61
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable prefer-destructuring */
|
|
2
|
+
|
|
1
3
|
/*!
|
|
2
4
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
5
|
*/
|
|
@@ -27,10 +29,12 @@ export default class RedirectInterceptor extends Interceptor {
|
|
|
27
29
|
*/
|
|
28
30
|
onRequest(options) {
|
|
29
31
|
if (options && options.uri && typeof options.uri === 'string') {
|
|
30
|
-
if (
|
|
32
|
+
if (
|
|
33
|
+
options.uri.includes('https://idbroker') ||
|
|
31
34
|
options.uri.includes(this.webex.config.credentials.samlUrl) ||
|
|
32
35
|
options.uri.includes(this.webex.config.credentials.tokenUrl) ||
|
|
33
|
-
options.uri.includes(this.webex.config.credentials.authorizeUrl)
|
|
36
|
+
options.uri.includes(this.webex.config.credentials.authorizeUrl)
|
|
37
|
+
) {
|
|
34
38
|
return options;
|
|
35
39
|
}
|
|
36
40
|
}
|
|
@@ -68,20 +72,22 @@ export default class RedirectInterceptor extends Interceptor {
|
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
return this.webex.request(options);
|
|
71
|
-
}
|
|
72
|
-
|
|
75
|
+
} else if (
|
|
76
|
+
response.headers &&
|
|
73
77
|
response.body &&
|
|
74
78
|
response.body.errorCode === LOCUS_REDIRECT_ERROR &&
|
|
75
|
-
response.body.location
|
|
79
|
+
response.body.location
|
|
80
|
+
) {
|
|
76
81
|
options = clone(options);
|
|
77
82
|
|
|
78
83
|
this.webex.logger.warn('redirect: url redirects needed from', options.uri);
|
|
79
|
-
if (response.options && response.options.qs) {
|
|
84
|
+
if (response.options && response.options.qs) {
|
|
85
|
+
// for POST requests
|
|
80
86
|
const newUrl = response.body.location.split('?');
|
|
81
87
|
|
|
82
88
|
options.uri = newUrl[0]; // params are already present in the qs
|
|
83
|
-
}
|
|
84
|
-
|
|
89
|
+
} else {
|
|
90
|
+
// for GET requests
|
|
85
91
|
options.uri = response.body.location;
|
|
86
92
|
}
|
|
87
93
|
|
|
@@ -26,8 +26,7 @@ export default class RequestEventInterceptor extends Interceptor {
|
|
|
26
26
|
|
|
27
27
|
try {
|
|
28
28
|
this.webex.trigger('request:start', options);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
29
|
+
} catch (error) {
|
|
31
30
|
logger.warn('event handler for request:start failed ', error);
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -48,8 +47,7 @@ export default class RequestEventInterceptor extends Interceptor {
|
|
|
48
47
|
try {
|
|
49
48
|
this.webex.trigger('request:end', options, reason);
|
|
50
49
|
this.webex.trigger('request:failure', options, reason);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
50
|
+
} catch (error) {
|
|
53
51
|
logger.warn('event handler for request:end failed ', error);
|
|
54
52
|
}
|
|
55
53
|
|
|
@@ -67,8 +65,7 @@ export default class RequestEventInterceptor extends Interceptor {
|
|
|
67
65
|
|
|
68
66
|
try {
|
|
69
67
|
this.webex.trigger('request:success', response.options, response);
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
68
|
+
} catch (error) {
|
|
72
69
|
logger.warn('event handler for request:success failed ', error);
|
|
73
70
|
}
|
|
74
71
|
|
|
@@ -87,8 +84,7 @@ export default class RequestEventInterceptor extends Interceptor {
|
|
|
87
84
|
try {
|
|
88
85
|
this.webex.trigger('request:end', options, reason);
|
|
89
86
|
this.webex.trigger('request:failure', options, reason);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
87
|
+
} catch (error) {
|
|
92
88
|
logger.warn('event handler for request:failure failed ', error);
|
|
93
89
|
}
|
|
94
90
|
|
|
@@ -40,14 +40,17 @@ export default class RequestLoggerInterceptor extends Interceptor {
|
|
|
40
40
|
try {
|
|
41
41
|
// Determine if body is a buffer without relying on Buffer to avoid
|
|
42
42
|
// node/browser conflicts.
|
|
43
|
-
if (
|
|
43
|
+
if (
|
|
44
|
+
options.body &&
|
|
45
|
+
options.body.length &&
|
|
46
|
+
!isArray(options.body) &&
|
|
47
|
+
!isString(options.body)
|
|
48
|
+
) {
|
|
44
49
|
logger.info('Request Options:', util.inspect(omit(options, 'body'), {depth: null}));
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
50
|
+
} else {
|
|
47
51
|
logger.info('Request Options:', util.inspect(options, {depth: null}));
|
|
48
52
|
}
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
53
|
+
} catch (e) {
|
|
51
54
|
logger.warn('Could not stringify request options:', e);
|
|
52
55
|
}
|
|
53
56
|
}
|
|
@@ -36,12 +36,10 @@ export default class ResponseLoggerInterceptor extends Interceptor {
|
|
|
36
36
|
logger.info('timestamp (end): ', now.getTime(), now.toISOString());
|
|
37
37
|
if (typeof response.body === 'string' || isBuffer(response.body)) {
|
|
38
38
|
logger.info('Response: ', 'Not printed, it`s probably a file');
|
|
39
|
-
}
|
|
40
|
-
else if (typeof response.body === 'object') {
|
|
39
|
+
} else if (typeof response.body === 'object') {
|
|
41
40
|
try {
|
|
42
41
|
logger.info('Response: ', util.inspect(omit(response.body, 'features'), {depth: null}));
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
42
|
+
} catch (err) {
|
|
45
43
|
logger.info('Response: ', '[Not Serializable]', err);
|
|
46
44
|
}
|
|
47
45
|
}
|
|
@@ -68,8 +66,7 @@ export default class ResponseLoggerInterceptor extends Interceptor {
|
|
|
68
66
|
logger.info('timestamp (end): ', now.getTime(), now.toISOString());
|
|
69
67
|
try {
|
|
70
68
|
logger.error('Response: ', util.inspect(reason.body, {depth: null}));
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
69
|
+
} catch (err) {
|
|
73
70
|
logger.error('Response: ', reason.body);
|
|
74
71
|
}
|
|
75
72
|
}
|
|
@@ -88,8 +85,14 @@ export default class ResponseLoggerInterceptor extends Interceptor {
|
|
|
88
85
|
const logger = get(this, 'webex.logger', console);
|
|
89
86
|
|
|
90
87
|
logger.info('Status Code:', response.statusCode);
|
|
91
|
-
logger.info(
|
|
88
|
+
logger.info(
|
|
89
|
+
'WEBEX_TRACKINGID:',
|
|
90
|
+
get(options, 'headers.trackingid') || get(response, 'headers.trackingid')
|
|
91
|
+
);
|
|
92
92
|
logger.info('Network duration:', options.$timings.networkEnd - options.$timings.networkStart);
|
|
93
|
-
logger.info(
|
|
93
|
+
logger.info(
|
|
94
|
+
'Processing duration:',
|
|
95
|
+
options.$timings.requestEnd - options.$timings.requestStart
|
|
96
|
+
);
|
|
94
97
|
}
|
|
95
98
|
}
|
|
@@ -41,8 +41,7 @@ export default class UserAgentInterceptor extends Interceptor {
|
|
|
41
41
|
super(options);
|
|
42
42
|
if (appName) {
|
|
43
43
|
strings.set(this, `${appName}/${appVersion}`);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
44
|
+
} else {
|
|
46
45
|
strings.set(this, '@webex/http-core'); // Using the traditional default from http-core
|
|
47
46
|
}
|
|
48
47
|
}
|