@asgardeo/auth-spa 0.2.11 → 0.2.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.
Files changed (54) hide show
  1. package/README.md +40 -36
  2. package/dist/asgardeo-spa.production.esm.js +19 -19
  3. package/dist/asgardeo-spa.production.esm.js.map +1 -1
  4. package/dist/asgardeo-spa.production.js +19 -19
  5. package/dist/asgardeo-spa.production.js.map +1 -1
  6. package/dist/asgardeo-spa.production.min.js +1 -1
  7. package/dist/asgardeo-spa.production.min.js.map +1 -1
  8. package/dist/polyfilled/asgardeo-spa.production.esm.js +41 -41
  9. package/dist/polyfilled/asgardeo-spa.production.esm.js.map +1 -1
  10. package/dist/polyfilled/asgardeo-spa.production.js +41 -41
  11. package/dist/polyfilled/asgardeo-spa.production.js.map +1 -1
  12. package/dist/polyfilled/asgardeo-spa.production.min.js +1 -1
  13. package/dist/polyfilled/asgardeo-spa.production.min.js.map +1 -1
  14. package/dist/src/client.d.ts +6 -6
  15. package/dist/src/client.d.ts.map +1 -1
  16. package/dist/src/client.js +7 -6
  17. package/dist/src/client.js.map +1 -1
  18. package/dist/src/clients/main-thread-client.d.ts.map +1 -1
  19. package/dist/src/clients/main-thread-client.js +125 -46
  20. package/dist/src/clients/main-thread-client.js.map +1 -1
  21. package/dist/src/clients/web-worker-client.d.ts.map +1 -1
  22. package/dist/src/clients/web-worker-client.js +42 -19
  23. package/dist/src/clients/web-worker-client.js.map +1 -1
  24. package/dist/src/constants/parameters.d.ts +1 -0
  25. package/dist/src/constants/parameters.d.ts.map +1 -1
  26. package/dist/src/constants/parameters.js +1 -0
  27. package/dist/src/constants/parameters.js.map +1 -1
  28. package/dist/src/http-client/clients/axios-http-client.d.ts.map +1 -1
  29. package/dist/src/http-client/clients/axios-http-client.js +8 -0
  30. package/dist/src/http-client/clients/axios-http-client.js.map +1 -1
  31. package/dist/src/models/client.d.ts +2 -2
  32. package/dist/src/models/client.d.ts.map +1 -1
  33. package/dist/src/models/http-client.d.ts +2 -1
  34. package/dist/src/models/http-client.d.ts.map +1 -1
  35. package/dist/src/models/web-worker.d.ts +1 -2
  36. package/dist/src/models/web-worker.d.ts.map +1 -1
  37. package/dist/src/worker/client.worker.d.ts.map +1 -1
  38. package/dist/src/worker/client.worker.js +1 -7
  39. package/dist/src/worker/client.worker.js.map +1 -1
  40. package/dist/src/worker/worker-core.d.ts.map +1 -1
  41. package/dist/src/worker/worker-core.js +20 -7
  42. package/dist/src/worker/worker-core.js.map +1 -1
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +6 -6
  45. package/src/client.ts +8 -7
  46. package/src/clients/main-thread-client.ts +149 -67
  47. package/src/clients/web-worker-client.ts +50 -24
  48. package/src/constants/parameters.ts +1 -0
  49. package/src/http-client/clients/axios-http-client.ts +10 -0
  50. package/src/models/client.ts +2 -2
  51. package/src/models/http-client.ts +2 -1
  52. package/src/models/web-worker.ts +1 -2
  53. package/src/worker/client.worker.ts +3 -12
  54. package/src/worker/worker-core.ts +20 -8
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Asgardeo Auth SPA SDK
2
2
 
3
3
  ![Builder](https://github.com/asgardeo/asgardeo-auth-spa-sdk/workflows/Builder/badge.svg)
4
- [![Stackoverflow](https://img.shields.io/badge/Ask%20for%20help%20on-Stackoverflow-orange)](https://stackoverflow.com/questions/tagged/wso2is)
4
+ [![Stackoverflow](https://img.shields.io/badge/Ask%20for%20help%20on-Stackoverflow-orange)](https://stackoverflow.com/questions/tagged/asgardeo)
5
5
  [![Join the chat at https://join.slack.com/t/wso2is/shared_invite/enQtNzk0MTI1OTg5NjM1LTllODZiMTYzMmY0YzljYjdhZGExZWVkZDUxOWVjZDJkZGIzNTE1NDllYWFhM2MyOGFjMDlkYzJjODJhOWQ4YjE](https://img.shields.io/badge/Join%20us%20on-Slack-%23e01563.svg)](https://join.slack.com/t/wso2is/shared_invite/enQtNzk0MTI1OTg5NjM1LTllODZiMTYzMmY0YzljYjdhZGExZWVkZDUxOWVjZDJkZGIzNTE1NDllYWFhM2MyOGFjMDlkYzJjODJhOWQ4YjE)
6
- [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/wso2/product-is/blob/master/LICENSE)
7
- [![Twitter](https://img.shields.io/twitter/follow/wso2.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=wso2)
6
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/asgardeo/asgardeo-auth-spa-sdk/blob/main/LICENSE)
7
+ [![Twitter](https://img.shields.io/twitter/follow/wso2.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=asgardeo)
8
8
 
9
9
  ---
10
10
 
@@ -61,6 +61,10 @@
61
61
 
62
62
  Asgardeo Auth SPA SDK for JavaScript allows Single Page Applications to use OIDC or OAuth2 authentication in a simple and secure way. By using Asgardeo and the JavaScript SPA SDK, developers will be able to add identity management to their Single Page Applications in a jiffy.
63
63
 
64
+ ## Prerequisite
65
+
66
+ Create an organization in Asgardeo if you don't already have one. The organization name you choose will be referred to as `<org_name>` throughout this document.
67
+
64
68
  ## Install
65
69
 
66
70
  Install the JavaScript library from the npm registry.
@@ -92,7 +96,7 @@ auth.initialize({
92
96
  signInRedirectURL: "http://localhost:3000/sign-in",
93
97
  signOutRedirectURL: "http://localhost:3000/dashboard",
94
98
  clientID: "client ID",
95
- serverOrigin: "https://localhost:9443"
99
+ serverOrigin: "https://api.asgardeo.io/t/<org_name>"
96
100
  });
97
101
 
98
102
  // To sign in, simply call the `signIn()` method.
@@ -119,7 +123,7 @@ auth.initialize({
119
123
  signInRedirectURL: "http://localhost:3000/sign-in",
120
124
  signOutRedirectURL: "http://localhost:3000/dashboard",
121
125
  clientID: "client ID",
122
- serverOrigin: "https://localhost:9443"
126
+ serverOrigin: "https://api.asgardeo.io/t/<org_name>"
123
127
  });
124
128
 
125
129
  // To sign in, simply call the `signIn()` method.
@@ -136,27 +140,21 @@ auth.on("sign-in", (response) => {
136
140
 
137
141
  ## Try Out the Sample Apps
138
142
 
139
- ### 1. Create a Service Provider
140
-
141
- Before trying out the sample apps, you need to a create a service provider in the Identity Server.
142
-
143
- 1. So, navigate to `https://localhost:9443/carbon" and click on `Add`under`Service Providers` in the left-hand menu panel.
144
-
145
- 2. Enter `Sample` as the name of the app and click on `Register`.
146
-
147
- 3. Then, expand the `Inbound Authentication Configuration` section. Under that, expand `OAuth/OpenID Connect Configuration` section and click on `Configure`.
143
+ ### 1. Create an Application in Asgardeo
148
144
 
149
- 4. Under `Allowed Grant Types` uncheck everything except `Code` and `Refresh Token`.
145
+ Before trying out the sample apps, you need to create an application in **Asgardeo**.
150
146
 
151
- 5. Enter the Callback URL(s). You can find the relevant callback URL(s) of each sample app in the [Running the sample apps](#2.-running-the-sample-apps) section.
152
-
153
- 6. Check `Allow authentication without the client secret`.
154
-
155
- 7. Click `Add` at the bottom.
156
-
157
- 8. Copy the `OAuth Client Key`.
158
-
159
- 9. Enable CORS for the client application by following this guide (https://is.docs.wso2.com/en/5.11.0/learn/cors/).
147
+ 1. Navigate to [**Asgardeo Console**](https://console.asgardeo.io/login) and click on **Applications** under **Develop** tab
148
+
149
+ 2. Click on **New Application** and then **Single Page Application**.
150
+
151
+ 3. Enter **Sample** as the name of the app and add the redirect URL(s). You can find the relevant redirect URL(s) of each sample app in the [Running the sample apps](#2-running-the-sample-apps) section.
152
+
153
+ 4. Click on Register. You will be navigated to management page of the **sample** application.
154
+
155
+ 5. Add `https://localhost:5000` to **Allowed Origins** under **Access** tab and check **Public client** option.
156
+
157
+ 6. Click on **Update** at the bottom.
160
158
 
161
159
  ### 2. Running the sample apps
162
160
 
@@ -238,7 +236,7 @@ An instance of the `AsgardeoSPAClient`.
238
236
 
239
237
  #### Description
240
238
 
241
- This returns a static instance of the `AsgardeoSPAClient`. The SDK allows you to create multiple instances of the `AsgardeoSPAClient`. To do so, you can pass an `id` into the `getInstance` method. If no instance has been created for the provided `id`, a new instance will be created and returned by this method. If an instance exists, then that instance will be returned. If no `id` is provided, the default instance will be returned. This allows the SDK to talk to multiple identity servers through the same app.
239
+ This returns a static instance of the `AsgardeoSPAClient`. The SDK allows you to create multiple instances of the `AsgardeoSPAClient`. To do so, you can pass an `id` into the `getInstance` method. If no instance has been created for the provided `id`, a new instance will be created and returned by this method. If an instance exists, then that instance will be returned. If no `id` is provided, the default instance will be returned. This allows the SDK to talk to multiple identity providers through the same app.
242
240
 
243
241
  Creating a static instance affords the developers the flexibility of using multiple files to implement the authentication logic. That is, you can have the sign in logic implemented on one page and the sign out logic on another.
244
242
 
@@ -282,7 +280,7 @@ const config = {
282
280
  signInRedirectURL: "http://localhost:3000/sign-in",
283
281
  signOutRedirectURL: "http://localhost:3000/dashboard",
284
282
  clientID: "client ID",
285
- serverOrigin: "https://localhost:9443"
283
+ serverOrigin: "https://api.asgardeo.io/t/<org_name>"
286
284
  }
287
285
 
288
286
  auth.initialize(config);
@@ -334,7 +332,7 @@ signIn(config?: SignInConfig, authorizationCode?: string, sessionState?: string)
334
332
 
335
333
  #### Description
336
334
 
337
- As the name implies, this method is used to sign-in users. This method will have to be called twice to implement the two phases of the authentication process. The first phase generates generates the authorization URl and takes the user to the single-sign-on page of the identity server, while second phase triggers the token request to complete the authentication process. So, this method should be called when initiating authentication and when the user is redirected back to the app after authentication themselves with the server.
335
+ As the name implies, this method is used to sign-in users. This method will have to be called twice to implement the two phases of the authentication process. The first phase generates generates the authorization URl and takes the user to the single-sign-on page of the Asgardeo, while second phase triggers the token request to complete the authentication process. So, this method should be called when initiating authentication and when the user is redirected back to the app after authentication themselves with the server.
338
336
 
339
337
  The `sign-in` hook is used to fire a callback function after signing in is successful. Check the [on()](#on) section for more information.
340
338
 
@@ -355,11 +353,11 @@ trySignInSilently();
355
353
  This method attempts to sign a user in silently by sending an authorization request with the `prompt` query parameter set to `none`.
356
354
  This will be useful when you want to sign a user in automatically while avoiding the browser redirects.
357
355
 
358
- This uses an iFrame to check if there is an active user session in the identity server by sending an authorization request. If the request returns an authorization code, then the token request is dispatched and the returned token is stored effectively signing the user in.
356
+ This uses an iFrame to check if there is an active user session in the Asgardeo by sending an authorization request. If the request returns an authorization code, then the token request is dispatched and the returned token is stored effectively signing the user in.
359
357
 
360
358
  To dispatch a token request, the `[signIn()](#signIn)` or this `trySignInSilently()` method should be called by the page/component rendered by the redirect URL.
361
359
 
362
- This returns a promise that resolves with a `[BasicUserInfo](#BasicUserInfo)` object following a successful sign in. If the user is not signed into the identity server, then the promise resolves with the boolean value of `false`.
360
+ This returns a promise that resolves with a `[BasicUserInfo](#BasicUserInfo)` object following a successful sign in. If the user is not signed into the Asgardeo, then the promise resolves with the boolean value of `false`.
363
361
 
364
362
  The `sign-in` hook is used to fire a callback function after signing in is successful. Check the [on()](#on) section for more information.
365
363
 
@@ -388,7 +386,7 @@ signOut();
388
386
 
389
387
  #### Description
390
388
 
391
- This method ends the user session at the Identity Server and logs the user out.
389
+ This method ends the user session at the Asgardeo and logs the user out.
392
390
 
393
391
  The `sign-out` hook is used to fire a callback function after signing out is successful. Check the [on()](#on) section for more information.
394
392
 
@@ -409,7 +407,12 @@ httpRequest(config: HttpRequestConfig): Promise<HttpResponse>;
409
407
  #### Arguments
410
408
 
411
409
  1. config: `[HttpRequestConfig](#httpRequestConfig)`
412
- A config object with the settings necessary to send http requests. This object is similar to the `AxiosRequestConfig` but provides an additional attribute called `attachToken` to allow you to specify if the access token should be attached to the request.
410
+ A config object with the settings necessary to send http requests. This object is similar to the `AxiosRequestConfig` but provides these additional attributes:
411
+
412
+ |Attribute|Type|Default|Description|
413
+ |--|--|--|--|
414
+ |`attachToken`|`boolean`|`true`|If set to `true`, the token will be attached to the request header.|
415
+ |`shouldEncodeToFormData`|`boolean`|`false`|If set to `true`, the request body will be encoded to `FormData`. The body (specified by the `data` attribute) should be a Javascript object. |
413
416
 
414
417
  #### Returns
415
418
 
@@ -417,7 +420,7 @@ A Promise that resolves with the response.
417
420
 
418
421
  #### Description
419
422
 
420
- This method is used to send http requests to the Identity Server. The developer doesn't need to manually attach the access token since this method does it automatically.
423
+ This method is used to send http requests to the Asgardeo. The developer doesn't need to manually attach the access token since this method does it automatically.
421
424
 
422
425
  If the `storage` type is set to `sessionStorage` or `localStorage`, the developer may choose to implement their own ways of sending http requests by obtaining the access token from the relevant storage medium and attaching it to the header. However, if the `storage` is set to `webWorker`, this is the _ONLY_ way http requests can be sent.
423
426
 
@@ -436,7 +439,7 @@ const requestConfig = {
436
439
  "Content-Type": "application/scim+json"
437
440
  },
438
441
  method: "GET",
439
- url: "https://localhost:9443/scim2/me"
442
+ url: "https://api.asgardeo.io/scim2/me"
440
443
  };
441
444
 
442
445
  return auth.httpRequest(requestConfig)
@@ -500,7 +503,7 @@ A Promise that resolves either with the response or the [`BasicUserInfo`](#Basic
500
503
 
501
504
  #### Description
502
505
 
503
- This method allows developers to use custom grants provided by their Identity Servers. This method accepts an object that has the following attributes as the argument.
506
+ This method allows developers to use custom grants provided by their Identity Providers. This method accepts an object that has the following attributes as the argument.
504
507
 
505
508
  The `custom-grant` hook is used to fire a callback function after a custom grant request is successful. Check the [on()](#on) section for more information.
506
509
 
@@ -723,7 +726,7 @@ If you are using TypeScript, you may want to use the `Hooks` enum that consists
723
726
  | `"revoke-access-token"` | `revokeAccessToken()` | A boolean value indicating if the process was successful or not |
724
727
  | `"custom-grant"` | `customGrant()` | Returns the response from the custom grant request. |
725
728
 
726
- **When the user signs out, the user is taken to the identity server's logout page and then redirected back to the SPA on successful log out. Hence, developers should ensure that the `"sign-out"` hook is called when the page the user is redirected to loads.**
729
+ **When the user signs out, the user is taken to the Asgardeo's logout page and then redirected back to the SPA on successful log out. Hence, developers should ensure that the `"sign-out"` hook is called when the page the user is redirected to loads.**
727
730
 
728
731
  #### Example
729
732
 
@@ -928,7 +931,7 @@ This table shows the extended attributes provided by the `Config` interface.
928
931
  | `prompt` | Optional | `string` | "" | Specifies the prompt type of an OIDC request |
929
932
  | `responseMode` | Optional | `ResponseMode` | `"query"` | Specifies the response mode. The value can either be `query` or `form_post` |
930
933
  | `scope` | Optional | `string[]` | `["openid"]` | Specifies the requested scopes. |
931
- | `serverOrigin` | Required | `string` | "" | The origin of the Identity Provider. eg: `https://www.asgardeo.io` |
934
+ | `serverOrigin` | Required | `string` | "" | The origin of the Identity Provider. eg: `https://api.asgardeo.io/t/<org_name>` |
932
935
  | `endpoints` | Optional | `OIDCEndpoints` | [OIDC Endpoints Default Values](#oidc-endpoints) | The OIDC endpoint URLs. The SDK will try to obtain the endpoint URLS | using the `.well-known` endpoint. If this fails, the SDK will use these endpoint URLs. If this attribute is not set, then the default endpoint URLs will be | used. However, if the `overrideWellEndpointConfig` is set to `true`, then this will override the endpoints obtained from the `.well-known` endpoint. |
933
936
  | `overrideWellEndpointConfig` | Optional | `boolean` | `false` | If this option is set to `true`, then the `endpoints` object will override endpoints obtained | from the `.well-known` endpoint. If this is set to `false`, then this will be used as a fallback if the request to the `.well-known` endpoint fails. |
934
937
  | `wellKnownEndpoint` | Optional | `string` | `"/oauth2/token/.well-known/openid-configuration"` | The URL of the `.well-known` endpoint. |
@@ -945,6 +948,7 @@ This table shows the extended attributes provided by the `Config` interface.
945
948
  | `allowedScopes` | `string` | The scopes allowed for the user. |
946
949
  | `tenantDomain` | `string` | The tenant domain to which the user belongs. |
947
950
  | `sessionState` | `string` | The session state. |
951
+ | `sub` | `string` | The `uid` corresponding to the user to whom the ID token belongs to. |
948
952
 
949
953
  ### SignInConfig
950
954