@auth0/auth0-spa-js 2.18.2 → 2.18.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/auth0-spa-js.development.js +70 -3
- package/dist/auth0-spa-js.development.js.map +1 -1
- package/dist/auth0-spa-js.production.esm.js +1 -1
- package/dist/auth0-spa-js.production.esm.js.map +1 -1
- package/dist/auth0-spa-js.production.js +1 -1
- package/dist/auth0-spa-js.production.js.map +1 -1
- package/dist/auth0-spa-js.worker.development.js +41 -1
- package/dist/auth0-spa-js.worker.development.js.map +1 -1
- package/dist/auth0-spa-js.worker.production.js +1 -1
- package/dist/auth0-spa-js.worker.production.js.map +1 -1
- package/dist/lib/auth0-spa-js.cjs.js +70 -3
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/version.d.ts +1 -1
- package/dist/typings/worker/worker.types.d.ts +5 -0
- package/package.json +2 -2
- package/src/Auth0Client.ts +5 -0
- package/src/version.ts +1 -1
- package/src/worker/__mocks__/token.worker.ts +3 -3
- package/src/worker/token.worker.ts +59 -3
- package/src/worker/worker.types.ts +7 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "2.18.
|
|
1
|
+
declare const _default: "2.18.3";
|
|
2
2
|
export default _default;
|
|
@@ -2,6 +2,10 @@ import { FetchOptions } from '../global';
|
|
|
2
2
|
/**
|
|
3
3
|
* @ts-ignore
|
|
4
4
|
*/
|
|
5
|
+
export type WorkerInitMessage = {
|
|
6
|
+
type: 'init';
|
|
7
|
+
allowedBaseUrl: string;
|
|
8
|
+
};
|
|
5
9
|
export type WorkerRefreshTokenMessage = {
|
|
6
10
|
timeout: number;
|
|
7
11
|
fetchUrl: string;
|
|
@@ -13,3 +17,4 @@ export type WorkerRefreshTokenMessage = {
|
|
|
13
17
|
scope: string;
|
|
14
18
|
};
|
|
15
19
|
};
|
|
20
|
+
export type WorkerMessage = WorkerInitMessage | WorkerRefreshTokenMessage;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@auth0/auth0-spa-js",
|
|
4
4
|
"description": "Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "2.18.
|
|
6
|
+
"version": "2.18.3",
|
|
7
7
|
"main": "dist/lib/auth0-spa-js.cjs.js",
|
|
8
8
|
"types": "dist/typings/index.d.ts",
|
|
9
9
|
"module": "dist/auth0-spa-js.production.esm.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"serve:coverage": "serve coverage/lcov-report -n",
|
|
52
52
|
"serve:stats": "serve bundle-stats -n",
|
|
53
53
|
"print-bundle-size": "node ./scripts/print-bundle-size.mjs",
|
|
54
|
-
"prepack": "npm run build && npm run build:types
|
|
54
|
+
"prepack": "npm run build && npm run build:types",
|
|
55
55
|
"publish:cdn": "ccu --trace"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
package/src/Auth0Client.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '2.18.
|
|
1
|
+
export default '2.18.3';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { messageRouter } = jest.requireActual('../token.worker');
|
|
2
2
|
|
|
3
3
|
export default class {
|
|
4
4
|
postMessage(data, ports) {
|
|
5
|
-
|
|
5
|
+
messageRouter({
|
|
6
6
|
data,
|
|
7
|
-
ports
|
|
7
|
+
ports: ports || []
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MissingRefreshTokenError } from '../errors';
|
|
2
2
|
import { FetchResponse } from '../global';
|
|
3
3
|
import { createQueryParams, fromEntries } from '../utils';
|
|
4
|
-
import { WorkerRefreshTokenMessage } from './worker.types';
|
|
4
|
+
import { WorkerMessage, WorkerRefreshTokenMessage } from './worker.types';
|
|
5
5
|
|
|
6
6
|
let refreshTokens: Record<string, string> = {};
|
|
7
|
+
let allowedBaseUrl: string | null = null;
|
|
7
8
|
|
|
8
9
|
const cacheKey = (audience: string, scope: string) => `${audience}|${scope}`;
|
|
9
10
|
|
|
@@ -180,11 +181,66 @@ const messageHandler = async ({
|
|
|
180
181
|
}
|
|
181
182
|
};
|
|
182
183
|
|
|
184
|
+
const isAuthorizedWorkerRequest = (
|
|
185
|
+
workerRequest: WorkerRefreshTokenMessage
|
|
186
|
+
) => {
|
|
187
|
+
if (!allowedBaseUrl) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
const allowedBaseOrigin = new URL(allowedBaseUrl).origin;
|
|
193
|
+
const requestedUrl = new URL(workerRequest.fetchUrl);
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
requestedUrl.origin === allowedBaseOrigin &&
|
|
197
|
+
requestedUrl.pathname === '/oauth/token'
|
|
198
|
+
);
|
|
199
|
+
} catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const messageRouter = (event: MessageEvent<WorkerMessage>) => {
|
|
205
|
+
const { data, ports } = event;
|
|
206
|
+
const [port] = ports;
|
|
207
|
+
|
|
208
|
+
if ('type' in data && data.type === 'init') {
|
|
209
|
+
if (allowedBaseUrl === null) {
|
|
210
|
+
try {
|
|
211
|
+
new URL(data.allowedBaseUrl);
|
|
212
|
+
allowedBaseUrl = data.allowedBaseUrl;
|
|
213
|
+
} catch {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (
|
|
222
|
+
!('fetchUrl' in data) ||
|
|
223
|
+
!isAuthorizedWorkerRequest(data as WorkerRefreshTokenMessage)
|
|
224
|
+
) {
|
|
225
|
+
port?.postMessage({
|
|
226
|
+
ok: false,
|
|
227
|
+
json: {
|
|
228
|
+
error: 'invalid_fetch_url',
|
|
229
|
+
error_description: 'Unauthorized fetch URL'
|
|
230
|
+
},
|
|
231
|
+
headers: {}
|
|
232
|
+
});
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
messageHandler(event as MessageEvent<WorkerRefreshTokenMessage>);
|
|
237
|
+
};
|
|
238
|
+
|
|
183
239
|
// Don't run `addEventListener` in our tests (this is replaced in rollup)
|
|
184
240
|
if (process.env.NODE_ENV === 'test') {
|
|
185
|
-
module.exports = { messageHandler };
|
|
241
|
+
module.exports = { messageHandler, messageRouter };
|
|
186
242
|
/* c8 ignore next 4 */
|
|
187
243
|
} else {
|
|
188
244
|
// @ts-ignore
|
|
189
|
-
addEventListener('message',
|
|
245
|
+
addEventListener('message', messageRouter);
|
|
190
246
|
}
|
|
@@ -3,6 +3,11 @@ import { FetchOptions } from '../global';
|
|
|
3
3
|
/**
|
|
4
4
|
* @ts-ignore
|
|
5
5
|
*/
|
|
6
|
+
export type WorkerInitMessage = {
|
|
7
|
+
type: 'init';
|
|
8
|
+
allowedBaseUrl: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
6
11
|
export type WorkerRefreshTokenMessage = {
|
|
7
12
|
timeout: number;
|
|
8
13
|
fetchUrl: string;
|
|
@@ -14,3 +19,5 @@ export type WorkerRefreshTokenMessage = {
|
|
|
14
19
|
scope: string;
|
|
15
20
|
};
|
|
16
21
|
};
|
|
22
|
+
|
|
23
|
+
export type WorkerMessage = WorkerInitMessage | WorkerRefreshTokenMessage;
|