@asgardeo/auth-spa 0.4.6 → 0.4.9
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/asgardeo-spa.production.esm.js +16 -35
- package/dist/asgardeo-spa.production.esm.js.map +1 -1
- package/dist/asgardeo-spa.production.js +9 -28
- package/dist/asgardeo-spa.production.js.map +1 -1
- package/dist/asgardeo-spa.production.min.js +1 -1
- package/dist/asgardeo-spa.production.min.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.esm.js +882 -905
- package/dist/polyfilled/asgardeo-spa.production.esm.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.js +882 -905
- package/dist/polyfilled/asgardeo-spa.production.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.min.js +1 -1
- package/dist/polyfilled/asgardeo-spa.production.min.js.map +1 -1
- package/dist/src/client.js +3 -3
- package/dist/src/client.js.map +1 -1
- package/dist/src/clients/web-worker-client.d.ts.map +1 -1
- package/dist/src/clients/web-worker-client.js +13 -0
- package/dist/src/clients/web-worker-client.js.map +1 -1
- package/dist/src/utils/crypto-utils.d.ts.map +1 -1
- package/dist/src/utils/crypto-utils.js +4 -0
- package/dist/src/utils/crypto-utils.js.map +1 -1
- package/dist/src/worker/worker-receiver.d.ts.map +1 -1
- package/dist/src/worker/worker-receiver.js +16 -3
- package/dist/src/worker/worker-receiver.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/client.ts +3 -3
- package/src/clients/web-worker-client.ts +19 -5
- package/src/utils/crypto-utils.ts +7 -1
- package/src/worker/worker-receiver.ts +15 -2
|
@@ -113,13 +113,13 @@ export const WebWorkerClient = async (
|
|
|
113
113
|
const _requestTimeout: number = config?.requestTimeout ?? 60000;
|
|
114
114
|
let _isHttpHandlerEnabled: boolean = true;
|
|
115
115
|
let _getSignOutURLFromSessionStorage: boolean = false;
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
const _store: Store = initiateStore(config.storage);
|
|
118
118
|
const _cryptoUtils: SPACryptoUtils = new SPACryptoUtils();
|
|
119
119
|
const _authenticationClient = new AsgardeoAuthClient<WebWorkerClientConfig>(_store, _cryptoUtils);
|
|
120
120
|
await _authenticationClient.initialize(config);
|
|
121
121
|
const _spaHelper = new SPAHelper<WebWorkerClientConfig>(_authenticationClient);
|
|
122
|
-
|
|
122
|
+
|
|
123
123
|
const _sessionManagementHelper = await SessionManagementHelper(
|
|
124
124
|
async () => {
|
|
125
125
|
const message: Message<string> = {
|
|
@@ -138,7 +138,7 @@ export const WebWorkerClient = async (
|
|
|
138
138
|
(sessionState: string) => setSessionState(sessionState)
|
|
139
139
|
);
|
|
140
140
|
|
|
141
|
-
const _authenticationHelper: AuthenticationHelper<WebWorkerClientConfig> =
|
|
141
|
+
const _authenticationHelper: AuthenticationHelper<WebWorkerClientConfig> =
|
|
142
142
|
getAuthHelper(_authenticationClient, _spaHelper);
|
|
143
143
|
|
|
144
144
|
const worker: Worker = new webWorker();
|
|
@@ -163,6 +163,8 @@ export const WebWorkerClient = async (
|
|
|
163
163
|
|
|
164
164
|
return (channel.port1.onmessage = ({ data }: { data: ResponseMessage<string>; }) => {
|
|
165
165
|
clearTimeout(timer);
|
|
166
|
+
channel.port1.close();
|
|
167
|
+
channel.port2.close();
|
|
166
168
|
|
|
167
169
|
if (data?.success) {
|
|
168
170
|
const responseData = data?.data ? JSON.parse(data?.data) : null;
|
|
@@ -214,6 +216,18 @@ export const WebWorkerClient = async (
|
|
|
214
216
|
* @returns {Promise<HttpResponse>} A promise that resolves with the response data.
|
|
215
217
|
*/
|
|
216
218
|
const httpRequest = <T = any>(config: HttpRequestConfig): Promise<HttpResponse<T>> => {
|
|
219
|
+
/**
|
|
220
|
+
*
|
|
221
|
+
* Currently FormData is not supported to send to a web worker
|
|
222
|
+
*
|
|
223
|
+
* Below workaround will represent FormData object as a JSON.
|
|
224
|
+
* This workaround will not be needed once FormData object is made cloneable
|
|
225
|
+
* Reference: https://github.com/whatwg/xhr/issues/55
|
|
226
|
+
*/
|
|
227
|
+
if(config?.data && config?.data instanceof FormData) {
|
|
228
|
+
config.data = { ...Object.fromEntries(config?.data.entries()), formData: true };
|
|
229
|
+
}
|
|
230
|
+
|
|
217
231
|
const message: Message<HttpRequestConfig> = {
|
|
218
232
|
data: config,
|
|
219
233
|
type: HTTP_REQUEST
|
|
@@ -517,7 +531,7 @@ export const WebWorkerClient = async (
|
|
|
517
531
|
return getBasicUserInfo();
|
|
518
532
|
}
|
|
519
533
|
}
|
|
520
|
-
|
|
534
|
+
|
|
521
535
|
/**
|
|
522
536
|
* Initiates the authentication flow.
|
|
523
537
|
*
|
|
@@ -558,7 +572,7 @@ export const WebWorkerClient = async (
|
|
|
558
572
|
if (resolvedAuthorizationCode && resolvedState) {
|
|
559
573
|
return requestAccessToken(resolvedAuthorizationCode, resolvedSessionState, resolvedState);
|
|
560
574
|
}
|
|
561
|
-
|
|
575
|
+
|
|
562
576
|
return getAuthorizationURL(params)
|
|
563
577
|
.then(async (response: AuthorizationResponse) => {
|
|
564
578
|
location.href = response.authorizationURL;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { Buffer } from "buffer";
|
|
20
|
-
import { CryptoUtils, JWKInterface } from "@asgardeo/auth-js";
|
|
20
|
+
import { AsgardeoAuthException, CryptoUtils, JWKInterface } from "@asgardeo/auth-js";
|
|
21
21
|
import base64url from "base64url";
|
|
22
22
|
import sha256 from "fast-sha256";
|
|
23
23
|
import { createLocalJWKSet, jwtVerify } from "jose";
|
|
@@ -69,6 +69,12 @@ export class SPACryptoUtils implements CryptoUtils<Buffer | string>
|
|
|
69
69
|
}
|
|
70
70
|
).then(() => {
|
|
71
71
|
return Promise.resolve(true);
|
|
72
|
+
}).catch((error) => {
|
|
73
|
+
return Promise.reject(new AsgardeoAuthException(
|
|
74
|
+
"SPA-CRYPTO-UTILS-VJ-IV01",
|
|
75
|
+
error?.reason ?? JSON.stringify(error),
|
|
76
|
+
`${error?.code} ${error?.claim}`
|
|
77
|
+
));
|
|
72
78
|
});
|
|
73
79
|
}
|
|
74
80
|
}
|
|
@@ -122,9 +122,21 @@ export const workerReceiver = (
|
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
break;
|
|
125
|
-
case HTTP_REQUEST:
|
|
125
|
+
case HTTP_REQUEST: {
|
|
126
|
+
const request = data.data;
|
|
127
|
+
const requestData = request?.data;
|
|
128
|
+
if(data.data?.data?.formData === true) {
|
|
129
|
+
const formData = new FormData();
|
|
130
|
+
for (const key in requestData) {
|
|
131
|
+
if(key === "formData") {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
formData.append(key, requestData[key])
|
|
135
|
+
}
|
|
136
|
+
request.data = formData;
|
|
137
|
+
}
|
|
126
138
|
webWorker
|
|
127
|
-
.httpRequest(
|
|
139
|
+
.httpRequest(request)
|
|
128
140
|
.then((response) => {
|
|
129
141
|
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
130
142
|
})
|
|
@@ -133,6 +145,7 @@ export const workerReceiver = (
|
|
|
133
145
|
});
|
|
134
146
|
|
|
135
147
|
break;
|
|
148
|
+
}
|
|
136
149
|
case HTTP_REQUEST_ALL:
|
|
137
150
|
webWorker
|
|
138
151
|
.httpRequestAll(data.data)
|