@asgardeo/browser 0.0.1

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.
Files changed (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +48 -0
  3. package/dist/AsgardeoBrowserClient.d.ts +28 -0
  4. package/dist/__legacy__/client.d.ts +651 -0
  5. package/dist/__legacy__/clients/index.d.ts +19 -0
  6. package/dist/__legacy__/clients/main-thread-client.d.ts +21 -0
  7. package/dist/__legacy__/clients/web-worker-client.d.ts +21 -0
  8. package/dist/__legacy__/constants/errors.d.ts +18 -0
  9. package/dist/__legacy__/constants/hooks.d.ts +29 -0
  10. package/dist/__legacy__/constants/index.d.ts +23 -0
  11. package/dist/__legacy__/constants/messages-types.d.ts +51 -0
  12. package/dist/__legacy__/constants/parameters.d.ts +21 -0
  13. package/dist/__legacy__/constants/session-management.d.ts +25 -0
  14. package/dist/__legacy__/constants/storage.d.ts +18 -0
  15. package/dist/__legacy__/helpers/authentication-helper.d.ts +58 -0
  16. package/dist/__legacy__/helpers/index.d.ts +20 -0
  17. package/dist/__legacy__/helpers/session-management-helper.d.ts +20 -0
  18. package/dist/__legacy__/helpers/spa-helper.d.ts +28 -0
  19. package/dist/__legacy__/http-client/clients/axios-http-client.d.ts +117 -0
  20. package/dist/__legacy__/http-client/clients/index.d.ts +19 -0
  21. package/dist/__legacy__/http-client/helpers/decorators.d.ts +24 -0
  22. package/dist/__legacy__/http-client/helpers/index.d.ts +19 -0
  23. package/dist/__legacy__/http-client/index.d.ts +20 -0
  24. package/dist/__legacy__/http-client/models/axios-http-client.d.ts +34 -0
  25. package/dist/__legacy__/http-client/models/http-client.d.ts +41 -0
  26. package/dist/__legacy__/http-client/models/index.d.ts +20 -0
  27. package/dist/__legacy__/models/client-config.d.ts +54 -0
  28. package/dist/__legacy__/models/client.d.ts +82 -0
  29. package/dist/__legacy__/models/http-client.d.ts +42 -0
  30. package/dist/__legacy__/models/index.d.ts +26 -0
  31. package/dist/__legacy__/models/message.d.ts +45 -0
  32. package/dist/__legacy__/models/request-custom-grant.d.ts +24 -0
  33. package/dist/__legacy__/models/session-management-helper.d.ts +23 -0
  34. package/dist/__legacy__/models/sign-in.d.ts +21 -0
  35. package/dist/__legacy__/models/sign-out-error.d.ts +21 -0
  36. package/dist/__legacy__/models/storage.d.ts +38 -0
  37. package/dist/__legacy__/models/web-worker.d.ts +55 -0
  38. package/dist/__legacy__/stores/index.d.ts +20 -0
  39. package/dist/__legacy__/stores/local-store.d.ts +23 -0
  40. package/dist/__legacy__/stores/memory-store.d.ts +25 -0
  41. package/dist/__legacy__/stores/session-store.d.ts +23 -0
  42. package/dist/__legacy__/utils/crypto-utils.d.ts +31 -0
  43. package/dist/__legacy__/utils/index.d.ts +19 -0
  44. package/dist/__legacy__/utils/message-utils.d.ts +37 -0
  45. package/dist/__legacy__/utils/spa-utils.d.ts +107 -0
  46. package/dist/__legacy__/worker/index.d.ts +19 -0
  47. package/dist/__legacy__/worker/worker-core.d.ts +21 -0
  48. package/dist/__legacy__/worker/worker-receiver.d.ts +21 -0
  49. package/dist/cjs/index.js +5437 -0
  50. package/dist/cjs/index.js.map +7 -0
  51. package/dist/constants/StyleConstants.d.ts +28 -0
  52. package/dist/index.d.ts +37 -0
  53. package/dist/index.js +5459 -0
  54. package/dist/index.js.map +7 -0
  55. package/dist/models/config.d.ts +19 -0
  56. package/dist/utils/hasAuthParamsInUrl.d.ts +25 -0
  57. package/dist/utils/withVendorCSSClassPrefix.d.ts +32 -0
  58. package/dist/worker.d.ts +21 -0
  59. package/package.json +76 -0
@@ -0,0 +1,651 @@
1
+ /**
2
+ * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3
+ *
4
+ * WSO2 Inc. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { AuthClientConfig, BasicUserInfo, IsomorphicCrypto, CustomGrantConfig, DataLayer, IdTokenPayload, FetchResponse, OIDCEndpoints } from '@asgardeo/javascript';
19
+ import { Hooks } from './constants';
20
+ import { AuthenticationHelper } from './helpers';
21
+ import { HttpClientInstance } from './http-client';
22
+ import { AuthSPAClientConfig, LegacyConfig as Config, HttpRequestConfig, HttpResponse, MainThreadClientConfig, MainThreadClientInterface, SignInConfig, SignOutError, WebWorkerClientConfig, WebWorkerClientInterface } from './models';
23
+ import { Storage } from './models/storage';
24
+ /**
25
+ * This class provides the necessary methods to implement authentication in a Single Page Application.
26
+ *
27
+ * @export
28
+ * @class AsgardeoSPAClient
29
+ */
30
+ export declare class AsgardeoSPAClient {
31
+ protected static _instances: Map<number, AsgardeoSPAClient>;
32
+ protected _client: WebWorkerClientInterface | MainThreadClientInterface | undefined;
33
+ protected _storage: Storage | undefined;
34
+ protected _authHelper: typeof AuthenticationHelper;
35
+ protected _worker: new () => Worker;
36
+ protected _initialized: boolean;
37
+ protected _startedInitialize: boolean;
38
+ protected _onSignInCallback: (response: BasicUserInfo) => void;
39
+ protected _onSignOutCallback: () => void;
40
+ protected _onSignOutFailedCallback: (error: SignOutError) => void;
41
+ protected _onEndUserSession: (response: any) => void;
42
+ protected _onInitialize: (response: boolean) => void;
43
+ protected _onCustomGrant: Map<string, (response: any) => void>;
44
+ protected _instanceID: number;
45
+ protected constructor(id: number);
46
+ instantiateAuthHelper(authHelper?: typeof AuthenticationHelper): void;
47
+ instantiateWorker(worker: new () => Worker): void;
48
+ /**
49
+ * This method specifies if the `AsgardeoSPAClient` has been initialized or not.
50
+ *
51
+ * @return {Promise<boolean>} - Resolves to `true` if the client has been initialized.
52
+ *
53
+ * @memberof AsgardeoSPAClient
54
+ *
55
+ * @private
56
+ */
57
+ private _isInitialized;
58
+ /**
59
+ * This method checks if the SDK is initialized and the user is authenticated.
60
+ *
61
+ * @param validateAuthentication - should user's authenticated status be checked as part of validation
62
+ *
63
+ * @return {Promise<boolean>} - A Promise that resolves with `true` if the SDK is initialized and the
64
+ * user is authenticated.
65
+ *
66
+ * @memberof AsgardeoSPAClient
67
+ *
68
+ * @private
69
+ */
70
+ private _validateMethod;
71
+ /**
72
+ * This method returns the instance of the singleton class.
73
+ * If an ID is provided, it will return the instance with the given ID.
74
+ * If no ID is provided, it will return the default instance value 0.
75
+ *
76
+ * @return {AsgardeoSPAClient} - Returns the instance of the singleton class.
77
+ *
78
+ * @example
79
+ * ```
80
+ * const auth = AsgardeoSPAClient.getInstance();
81
+ * ```
82
+ *
83
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getinstance
84
+ *
85
+ * @memberof AsgardeoSPAClient
86
+ *
87
+ * @preserve
88
+ */
89
+ static getInstance(id?: number): AsgardeoSPAClient | undefined;
90
+ /**
91
+ * This method initializes the `AsgardeoSPAClient` instance.
92
+ *
93
+ * @param {ConfigInterface} config The config object to initialize with.
94
+ *
95
+ * @return {Promise<boolean>} - Resolves to `true` if initialization is successful.
96
+ *
97
+ * @example
98
+ * ```
99
+ * auth.initialize({
100
+ * signInRedirectURL: "http://localhost:3000/sign-in",
101
+ * clientID: "client ID",
102
+ * baseUrl: "https://api.asgardeo.io"
103
+ * });
104
+ * ```
105
+ *
106
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#initialize
107
+ *
108
+ * @memberof AsgardeoSPAClient
109
+ *
110
+ * @preserve
111
+ */
112
+ initialize(config: AuthSPAClientConfig, authHelper?: typeof AuthenticationHelper, workerFile?: new () => Worker): Promise<boolean>;
113
+ /**
114
+ * This method returns a Promise that resolves with the basic user information obtained from the ID token.
115
+ *
116
+ * @return {Promise<BasicUserInfo>} - A promise that resolves with the user information.
117
+ *
118
+ * @example
119
+ * ```
120
+ * auth.getBasicUserInfo().then((response) => {
121
+ * // console.log(response);
122
+ * }).catch((error) => {
123
+ * // console.error(error);
124
+ * });
125
+ * ```
126
+ *
127
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getuserinfo
128
+ *
129
+ * @memberof AsgardeoSPAClient
130
+ *
131
+ * @preserve
132
+ */
133
+ getBasicUserInfo(): Promise<BasicUserInfo | undefined>;
134
+ /**
135
+ * This method initiates the authentication flow. This should be called twice.
136
+ * 1. To initiate the authentication flow.
137
+ * 2. To obtain the access token after getting the authorization code.
138
+ *
139
+ * To satisfy the second condition, one of the two strategies mentioned below can be used:
140
+ * 1. Redirect the user back to the same login page that initiated the authentication flow.
141
+ * 2. Call the `signIn()` method in the page the user is redirected to after authentication.
142
+ *
143
+ * **To fire a callback function after signing in, use the `on()` method.**
144
+ * **To learn more about the `on()` method:**
145
+ * @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
146
+ *
147
+ * @param {SignInConfig} config - The sign-in config.
148
+ * The `SignInConfig` object has these two attributes in addition to any custom key-value pairs.
149
+ * 1. fidp - Specifies the FIDP parameter that is used to take the user directly to an IdP login page.
150
+ * 2. forceInit: Specifies if the OIDC Provider Meta Data should be loaded again from the `well-known`
151
+ * endpoint.
152
+ * 3. Any other parameters that should be appended to the authorization request.
153
+ * @param {string} authorizationCode - The authorization code. (Optional)
154
+ * @param {string} sessionState - The session state. (Optional)
155
+ * @param {string} state - The state. (Optional)
156
+ *
157
+ * @return {Promise<BasicUserInfo>} - A promise that resolves with the user information.
158
+ *
159
+ * @example
160
+ * ```
161
+ * auth.signIn();
162
+ * ```
163
+ *
164
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#signin
165
+ *
166
+ * @memberof AsgardeoSPAClient
167
+ *
168
+ * @preserve
169
+ */
170
+ signIn(config?: SignInConfig, authorizationCode?: string, sessionState?: string, state?: string, tokenRequestConfig?: {
171
+ params: Record<string, unknown>;
172
+ }): Promise<BasicUserInfo | undefined>;
173
+ /**
174
+ * This method allows you to sign in silently.
175
+ * First, this method sends a prompt none request to see if there is an active user session in the identity server.
176
+ * If there is one, then it requests the access token and stores it. Else, it returns false.
177
+ *
178
+ * If this method is to be called on page load and the `signIn` method is also to be called on page load,
179
+ * then it is advisable to call this method after the `signIn` call.
180
+ *
181
+ * @return {Promise<BasicUserInfo | boolean>} - A Promise that resolves with the user information after signing in
182
+ * or with `false` if the user is not signed in.
183
+ *
184
+ * @example
185
+ *```
186
+ * auth.trySignInSilently()
187
+ *```
188
+ */
189
+ trySignInSilently(additionalParams?: Record<string, string | boolean>, tokenRequestConfig?: {
190
+ params: Record<string, unknown>;
191
+ }): Promise<BasicUserInfo | boolean | undefined>;
192
+ /**
193
+ * This method initiates the sign-out flow.
194
+ *
195
+ * **To fire a callback function after signing out, use the `on()` method.**
196
+ * **To learn more about the `on()` method:**
197
+ * @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
198
+ *
199
+ * @return {Promise<boolean>} - Returns a promise that resolves with `true` if sign out is successful.
200
+ *
201
+ * @example
202
+ * ```
203
+ * auth.signOut();
204
+ * ```
205
+ *
206
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#signout
207
+ *
208
+ * @memberof AsgardeoSPAClient
209
+ *
210
+ * @preserve
211
+ */
212
+ signOut(): Promise<boolean>;
213
+ /**
214
+ * This method sends an API request to a protected endpoint.
215
+ * The access token is automatically attached to the header of the request.
216
+ * This is the only way by which protected endpoints can be accessed
217
+ * when the web worker is used to store session information.
218
+ *
219
+ * @param {HttpRequestConfig} config - The config object containing attributes necessary to send a request.
220
+ *
221
+ * @return {Promise<HttpResponse>} - Returns a Promise that resolves with the response to the request.
222
+ *
223
+ * @example
224
+ * ```
225
+ * const requestConfig = {
226
+ * headers: {
227
+ * "Accept": "application/json",
228
+ * "Access-Control-Allow-Origin": "https://api.asgardeo.io/myaccount",
229
+ * "Content-Type": "application/scim+json"
230
+ * },
231
+ * method: "GET",
232
+ * url: "https://api.asgardeo.io/scim2/me"
233
+ * };
234
+ *
235
+ * return auth.httpRequest(requestConfig)
236
+ * .then((response) => {
237
+ * // console.log(response);
238
+ * })
239
+ * .catch((error) => {
240
+ * // console.error(error);
241
+ * });
242
+ * ```
243
+ *
244
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequest
245
+ *
246
+ * @memberof AsgardeoSPAClient
247
+ *
248
+ * @preserve
249
+ */
250
+ httpRequest(config: HttpRequestConfig): Promise<HttpResponse | undefined>;
251
+ /**
252
+ * This method sends multiple API requests to a protected endpoint.
253
+ * The access token is automatically attached to the header of the request.
254
+ * This is the only way by which multiple requests can be sent to protected endpoints
255
+ * when the web worker is used to store session information.
256
+ *
257
+ * @param {HttpRequestConfig[]} config - The config object containing attributes necessary to send a request.
258
+ *
259
+ * @return {Promise<HttpResponse[]>} - Returns a Promise that resolves with the responses to the requests.
260
+ *
261
+ * @example
262
+ * ```
263
+ * const requestConfig = {
264
+ * headers: {
265
+ * "Accept": "application/json",
266
+ * "Content-Type": "application/scim+json"
267
+ * },
268
+ * method: "GET",
269
+ * url: "https://api.asgardeo.io/scim2/me"
270
+ * };
271
+ *
272
+ * const requestConfig2 = {
273
+ * headers: {
274
+ * "Accept": "application/json",
275
+ * "Content-Type": "application/scim+json"
276
+ * },
277
+ * method: "GET",
278
+ * url: "https://api.asgardeo.io/scim2/me"
279
+ * };
280
+ *
281
+ * return auth.httpRequest([requestConfig, requestConfig2])
282
+ * .then((responses) => {
283
+ * response.forEach((response)=>{
284
+ * // console.log(response);
285
+ * });
286
+ * })
287
+ * .catch((error) => {
288
+ * // console.error(error);
289
+ * });
290
+ * ```
291
+ *
292
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequestall
293
+ *
294
+ * @memberof AsgardeoSPAClient
295
+ *
296
+ * @preserve
297
+ */
298
+ httpRequestAll(config: HttpRequestConfig[]): Promise<HttpResponse[] | undefined>;
299
+ /**
300
+ * This method allows you to send a request with a custom grant.
301
+ *
302
+ * @param {CustomGrantRequestParams} config - The request parameters.
303
+ *
304
+ * @return {Promise<HttpResponse<any> | SignInResponse>} - A Promise that resolves with
305
+ * the value returned by the custom grant request.
306
+ *
307
+ * @example
308
+ * ```
309
+ * auth.customGrant({
310
+ * attachToken: false,
311
+ * data: {
312
+ * client_id: "{{clientId}}",
313
+ * grant_type: "account_switch",
314
+ * scope: "{{scope}}",
315
+ * token: "{{token}}",
316
+ * },
317
+ * id: "account-switch",
318
+ * returnResponse: true,
319
+ * returnsSession: true,
320
+ * signInRequired: true
321
+ * });
322
+ * ```
323
+ *
324
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#customgrant
325
+ *
326
+ * @memberof AsgardeoSPAClient
327
+ *
328
+ * @preserve
329
+ */
330
+ requestCustomGrant(config: CustomGrantConfig): Promise<FetchResponse<any> | BasicUserInfo | undefined>;
331
+ /**
332
+ * This method ends a user session. The access token is revoked and the session information is destroyed.
333
+ *
334
+ * **To fire a callback function after ending user session, use the `on()` method.**
335
+ * **To learn more about the `on()` method:**
336
+ * @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
337
+ *
338
+ * @return {Promise<boolean>} - A promise that resolves with `true` if the process is successful.
339
+ *
340
+ * @example
341
+ * ```
342
+ * auth.endUserSession();
343
+ * ```
344
+ *
345
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#endusersession
346
+ *
347
+ * @memberof AsgardeoSPAClient
348
+ *
349
+ * @preserve
350
+ */
351
+ revokeAccessToken(): Promise<boolean | undefined>;
352
+ /**
353
+ * This method returns a Promise that resolves with an object containing the service endpoints.
354
+ *
355
+ * @return {Promise<ServiceResourcesType} - A Promise that resolves with an object containing the service endpoints.
356
+ *
357
+ * @example
358
+ * ```
359
+ * auth.getServiceEndpoints().then((endpoints) => {
360
+ * // console.log(endpoints);
361
+ * }).error((error) => {
362
+ * // console.error(error);
363
+ * });
364
+ * ```
365
+ *
366
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getserviceendpoints
367
+ *
368
+ * @memberof AsgardeoSPAClient
369
+ *
370
+ * @preserve
371
+ */
372
+ getOIDCServiceEndpoints(): Promise<OIDCEndpoints | undefined>;
373
+ /**
374
+ * This methods returns the Axios http client.
375
+ *
376
+ * @return {HttpClientInstance} - The Axios HTTP client.
377
+ *
378
+ * @memberof AsgardeoSPAClient
379
+ *
380
+ * @preserve
381
+ */
382
+ getHttpClient(): HttpClientInstance;
383
+ /**
384
+ * This method decodes the payload of the id token and returns it.
385
+ *
386
+ * @return {Promise<DecodedIdTokenPayloadInterface>} - A Promise that resolves with
387
+ * the decoded payload of the id token.
388
+ *
389
+ * @example
390
+ * ```
391
+ * auth.getDecodedIDToken().then((response)=>{
392
+ * // console.log(response);
393
+ * }).catch((error)=>{
394
+ * // console.error(error);
395
+ * });
396
+ * ```
397
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getdecodedidtoken
398
+ *
399
+ * @memberof AsgardeoSPAClient
400
+ *
401
+ * @preserve
402
+ */
403
+ getDecodedIDToken(): Promise<IdTokenPayload | undefined>;
404
+ /**
405
+ * This method returns the IsomorphicCrypto instance.
406
+ *
407
+ * @return {Promise<DecodedIdTokenPayloadInterface>} - A Promise that resolves with
408
+ * the IsomorphicCrypto instance.
409
+ *
410
+ * @example
411
+ * ```
412
+ * auth.getCryptoHelper().then((response)=>{
413
+ * // console.log(response);
414
+ * }).catch((error)=>{
415
+ * // console.error(error);
416
+ * });
417
+ * ```
418
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getCryptoHelper
419
+ *
420
+ * @memberof AsgardeoSPAClient
421
+ *
422
+ * @preserve
423
+ */
424
+ getCryptoHelper(): Promise<IsomorphicCrypto | undefined>;
425
+ /**
426
+ * This method return the ID token.
427
+ *
428
+ * @return {Promise<string>} - A Promise that resolves with the ID token.
429
+ *
430
+ * @example
431
+ * ```
432
+ * const idToken = await auth.getIDToken();
433
+ * ```
434
+ *
435
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken
436
+ *
437
+ * @memberof AsgardeoAuthClient
438
+ *
439
+ * @preserve
440
+ */
441
+ getIDToken(): Promise<string | undefined>;
442
+ /**
443
+ * This method return a Promise that resolves with the access token.
444
+ *
445
+ * **This method will not return the access token if the storage type is set to `webWorker`.**
446
+ *
447
+ * @return {Promise<string>} - A Promise that resolves with the access token.
448
+ *
449
+ * @example
450
+ * ```
451
+ * auth.getAccessToken().then((token) => {
452
+ * // console.log(token);
453
+ * }).catch((error) => {
454
+ * // console.error(error);
455
+ * });
456
+ * ```
457
+ *
458
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getaccesstoken
459
+ *
460
+ * @memberof AsgardeoSPAClient
461
+ *
462
+ * @preserve
463
+ */
464
+ getAccessToken(): Promise<string>;
465
+ /**
466
+ * This method return a Promise that resolves with the idp access token.
467
+ *
468
+ * **This method will not return the access token if the storage type is set to `webWorker`.**
469
+ *
470
+ * @return {Promise<string>} - A Promise that resolves with the idp access token.
471
+ *
472
+ * @example
473
+ * ```
474
+ * auth.getIDPAccessToken().then((token) => {
475
+ * // console.log(token);
476
+ * }).catch((error) => {
477
+ * // console.error(error);
478
+ * });
479
+ * ```
480
+ *
481
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getaccesstoken
482
+ *
483
+ * @memberof AsgardeoSPAClient
484
+ *
485
+ * @preserve
486
+ */
487
+ getIDPAccessToken(): Promise<string>;
488
+ /**
489
+ * This method return a Promise that resolves with the data layer object.
490
+ *
491
+ * **This method will not return the data layer object, if the storage type is set to `webWorker`.**
492
+ *
493
+ * @return {Promise<string>} - A Promise that resolves with the data layer object.
494
+ *
495
+ * @example
496
+ * ```
497
+ * auth.getDataLayer().then((dataLayer) => {
498
+ * // console.log(dataLayer);
499
+ * }).catch((error) => {
500
+ * // console.error(error);
501
+ * });
502
+ * ```
503
+ *
504
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getdatalayer
505
+ *
506
+ * @memberof AsgardeoSPAClient
507
+ *
508
+ * @preserve
509
+ */
510
+ getDataLayer(): Promise<DataLayer<MainThreadClientConfig>>;
511
+ /**
512
+ * This method return a Promise that resolves with the config data stored in the storage.
513
+ *
514
+ * @return - A Promise that resolves with the config data.
515
+ *
516
+ * @example
517
+ * ```
518
+ * auth.getConfigData().then((configData) => {
519
+ * // console.log(configData);
520
+ * }).catch((error) => {
521
+ * // console.error(error);
522
+ * });
523
+ * ```
524
+ *
525
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/main#getConfigData
526
+ *
527
+ * @memberof AsgardeoSPAClient
528
+ *
529
+ * @preserve
530
+ */
531
+ getConfigData(): Promise<AuthClientConfig<MainThreadClientConfig> | AuthClientConfig<WebWorkerClientConfig> | undefined>;
532
+ /**
533
+ * This method refreshes the access token.
534
+ *
535
+ * @return {TokenResponseInterface} - A Promise that resolves with an object containing
536
+ * information about the refreshed access token.
537
+ *
538
+ * @example
539
+ * ```
540
+ * auth.refreshToken().then((response)=>{
541
+ * // console.log(response);
542
+ * }).catch((error)=>{
543
+ * // console.error(error);
544
+ * });
545
+ * ```
546
+ *
547
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#refreshtoken
548
+ *
549
+ * @memberof AsgardeoSPAClient
550
+ *
551
+ * @preserve
552
+ */
553
+ refreshAccessToken(): Promise<BasicUserInfo | undefined>;
554
+ /**
555
+ * This method specifies if the user is authenticated or not.
556
+ *
557
+ * @return {Promise<boolean>} - A Promise that resolves with `true` if the user is authenticated.
558
+ *
559
+ * @memberof AsgardeoSPAClient
560
+ *
561
+ * @preserve
562
+ */
563
+ isAuthenticated(): Promise<boolean | undefined>;
564
+ /**
565
+ * This method specifies if there is an active session in the browser or not.
566
+ *
567
+ * @return {Promise<boolean>} - A Promise that resolves with `true` if there is a session.
568
+ *
569
+ * @memberof AsgardeoSPAClient
570
+ *
571
+ * @preserve
572
+ */
573
+ isSessionActive(): Promise<boolean | undefined>;
574
+ /**
575
+ * This method attaches a callback function to an event hook that fires the callback when the event happens.
576
+ *
577
+ * @param {Hooks.CustomGrant} hook - The name of the hook.
578
+ * @param {(response?: any) => void} callback - The callback function.
579
+ * @param {string} id (optional) - The id of the hook. This is used when multiple custom grants are used.
580
+ *
581
+ * @example
582
+ * ```
583
+ * auth.on("sign-in", (response)=>{
584
+ * // console.log(response);
585
+ * });
586
+ * ```
587
+ *
588
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on
589
+ *
590
+ * @memberof AsgardeoSPAClient
591
+ *
592
+ * @preserve
593
+ */
594
+ on(hook: Hooks.CustomGrant, callback: (response?: any) => void, id: string): Promise<void>;
595
+ on(hook: Exclude<Hooks, Hooks.CustomGrant>, callback: (response?: any) => void): Promise<void>;
596
+ /**
597
+ * This method enables callback functions attached to the http client.
598
+ *
599
+ * @return {Promise<boolean>} - A promise that resolves with True.
600
+ *
601
+ * @example
602
+ * ```
603
+ * auth.enableHttpHandler();
604
+ * ```
605
+ *
606
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#enableHttpHandler
607
+ *
608
+ * @memberof AsgardeoSPAClient
609
+ *
610
+ * @preserve
611
+ */
612
+ enableHttpHandler(): Promise<boolean | undefined>;
613
+ /**
614
+ * This method disables callback functions attached to the http client.
615
+ *
616
+ * @return {Promise<boolean>} - A promise that resolves with True.
617
+ *
618
+ * @example
619
+ * ```
620
+ * auth.disableHttpHandler();
621
+ * ```
622
+ *
623
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#disableHttpHandler
624
+ *
625
+ * @memberof AsgardeoSPAClient
626
+ *
627
+ * @preserve
628
+ */
629
+ disableHttpHandler(): Promise<boolean | undefined>;
630
+ /**
631
+ * This method updates the configuration that was passed into the constructor when instantiating this class.
632
+ *
633
+ * @param {Partial<AuthClientConfig<T>>} config - A config object to update the SDK configurations with.
634
+ *
635
+ * @example
636
+ * ```
637
+ * const config = {
638
+ * signInRedirectURL: "http://localhost:3000/sign-in",
639
+ * clientID: "client ID",
640
+ * baseUrl: "https://api.asgardeo.io"
641
+ * }
642
+ * const auth.updateConfig(config);
643
+ * ```
644
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master/lib#updateConfig
645
+ *
646
+ * @memberof AsgardeoAuthClient
647
+ *
648
+ * @preserve
649
+ */
650
+ updateConfig(config: Partial<AuthClientConfig<Config>>): Promise<void>;
651
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3
+ *
4
+ * WSO2 Inc. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ export * from "./main-thread-client";
19
+ export * from "./web-worker-client";
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3
+ *
4
+ * WSO2 Inc. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { AsgardeoAuthClient, AuthClientConfig } from '@asgardeo/javascript';
19
+ import { AuthenticationHelper, SPAHelper } from '../helpers';
20
+ import { MainThreadClientConfig, MainThreadClientInterface } from '../models';
21
+ export declare const MainThreadClient: (instanceID: number, config: AuthClientConfig<MainThreadClientConfig>, getAuthHelper: (authClient: AsgardeoAuthClient<MainThreadClientConfig>, spaHelper: SPAHelper<MainThreadClientConfig>) => AuthenticationHelper<MainThreadClientConfig>) => Promise<MainThreadClientInterface>;