@asgardeo/auth-spa 0.4.0 → 0.4.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.
Files changed (68) hide show
  1. package/README.md +44 -21
  2. package/dist/asgardeo-spa.production.esm.js +45 -9
  3. package/dist/asgardeo-spa.production.esm.js.map +1 -1
  4. package/dist/asgardeo-spa.production.js +44 -8
  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 +74 -38
  9. package/dist/polyfilled/asgardeo-spa.production.esm.js.map +1 -1
  10. package/dist/polyfilled/asgardeo-spa.production.js +74 -38
  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 +22 -1
  15. package/dist/src/client.d.ts.map +1 -1
  16. package/dist/src/client.js +29 -2
  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 +10 -1
  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 +27 -1
  23. package/dist/src/clients/web-worker-client.js.map +1 -1
  24. package/dist/src/constants/messages-types.d.ts +2 -0
  25. package/dist/src/constants/messages-types.d.ts.map +1 -1
  26. package/dist/src/constants/messages-types.js +2 -0
  27. package/dist/src/constants/messages-types.js.map +1 -1
  28. package/dist/src/helpers/authentication-helper.d.ts +4 -1
  29. package/dist/src/helpers/authentication-helper.d.ts.map +1 -1
  30. package/dist/src/helpers/authentication-helper.js +16 -0
  31. package/dist/src/helpers/authentication-helper.js.map +1 -1
  32. package/dist/src/helpers/session-management-helper.d.ts.map +1 -1
  33. package/dist/src/helpers/session-management-helper.js +0 -1
  34. package/dist/src/helpers/session-management-helper.js.map +1 -1
  35. package/dist/src/models/client.d.ts +4 -1
  36. package/dist/src/models/client.d.ts.map +1 -1
  37. package/dist/src/models/http-client.d.ts +1 -0
  38. package/dist/src/models/http-client.d.ts.map +1 -1
  39. package/dist/src/models/message.d.ts +2 -2
  40. package/dist/src/models/message.d.ts.map +1 -1
  41. package/dist/src/models/web-worker.d.ts +3 -1
  42. package/dist/src/models/web-worker.d.ts.map +1 -1
  43. package/dist/src/models/web-worker.js.map +1 -1
  44. package/dist/src/public-api.d.ts +3 -0
  45. package/dist/src/public-api.d.ts.map +1 -1
  46. package/dist/src/public-api.js +5 -0
  47. package/dist/src/public-api.js.map +1 -1
  48. package/dist/src/worker/worker-core.d.ts.map +1 -1
  49. package/dist/src/worker/worker-core.js +14 -1
  50. package/dist/src/worker/worker-core.js.map +1 -1
  51. package/dist/src/worker/worker-receiver.d.ts.map +1 -1
  52. package/dist/src/worker/worker-receiver.js +9 -1
  53. package/dist/src/worker/worker-receiver.js.map +1 -1
  54. package/dist/tsconfig.tsbuildinfo +1 -1
  55. package/package.json +2 -2
  56. package/src/client.ts +31 -4
  57. package/src/clients/main-thread-client.ts +18 -4
  58. package/src/clients/web-worker-client.ts +33 -0
  59. package/src/constants/messages-types.ts +2 -0
  60. package/src/helpers/authentication-helper.ts +13 -0
  61. package/src/helpers/session-management-helper.ts +0 -1
  62. package/src/models/client.ts +4 -0
  63. package/src/models/http-client.ts +1 -0
  64. package/src/models/message.ts +4 -0
  65. package/src/models/web-worker.ts +3 -0
  66. package/src/public-api.ts +7 -0
  67. package/src/worker/worker-core.ts +22 -4
  68. package/src/worker/worker-receiver.ts +9 -0
package/README.md CHANGED
@@ -31,7 +31,9 @@
31
31
  - [getOIDCServiceEndpoints](#getOIDCServiceEndpoints)
32
32
  - [getDecodedIDToken](#getdecodedidtoken)
33
33
  - [getIDToken](#getIDToken)
34
+ - [getCryptoHelper](#getCryptoHelper)
34
35
  - [getAccessToken](#getaccesstoken)
36
+ - [getIDPAccessToken](#getIDPAccessToken)
35
37
  - [refreshAccessToken](#refreshAccessToken)
36
38
  - [on](#on)
37
39
  - [isAuthenticated](#isAuthenticated)
@@ -239,7 +241,7 @@ An instance of the `AsgardeoSPAClient`.
239
241
 
240
242
  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.
241
243
 
242
- 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
+ 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.
243
245
 
244
246
  #### Example
245
247
 
@@ -268,7 +270,7 @@ initialize(config?: `AuthClientConfig<Config>`): Promise<void>;
268
270
 
269
271
  #### Description
270
272
 
271
- The `initialize` method is used to the initialize the client. This _MUST_ be called soon after instantiating the `AsgardeoSPAClient` and before calling another methods.
273
+ The `initialize` method is used to initialize the client. This _MUST_ be called soon after instantiating the `AsgardeoSPAClient` and before calling another methods.
272
274
 
273
275
  This method takes a `config` object as the only argument. The attributes of the `config` object is as follows.
274
276
 
@@ -333,7 +335,7 @@ signIn(config?: SignInConfig, authorizationCode?: string, sessionState?: string)
333
335
 
334
336
  #### Description
335
337
 
336
- 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
+ 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 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.
337
339
 
338
340
  The `sign-in` hook is used to fire a callback function after signing in is successful. Check the [on()](#on) section for more information.
339
341
 
@@ -416,6 +418,7 @@ httpRequest(config: HttpRequestConfig): Promise<HttpResponse>;
416
418
  |--------------------------|-----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------|
417
419
  | `attachToken` | `boolean` | `true` | If set to `true`, the token will be attached to the request header. |
418
420
  | `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. |
421
+ | `shouldAttachIDPAccessToken` | `boolean` | `false` | If set to `true`, the IDP access token will be attached to the the request `Authorization` header. |
419
422
 
420
423
  #### Returns
421
424
 
@@ -423,7 +426,7 @@ A Promise that resolves with the response.
423
426
 
424
427
  #### Description
425
428
 
426
- 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.
429
+ This method is used to send http requests to the Asgardeo authenticated endpoints. The developer doesn't need to manually attach the access token since this method does it automatically.
427
430
 
428
431
  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.
429
432
 
@@ -650,7 +653,7 @@ A Promise that resolves with the access token.
650
653
 
651
654
  #### Description
652
655
 
653
- This returns a promise that resolves with the access token. The promise resolves successfully only if the storage type is set to a type other than `webWorker`. Otherwise an error is thrown.
656
+ This returns a promise that resolves with the access token. The promise resolves successfully only if the storage type is set to a type other than `webWorker`. Otherwise, an error is thrown.
654
657
 
655
658
  #### Example
656
659
 
@@ -676,7 +679,7 @@ A Promise that resolves with the idp access token.
676
679
 
677
680
  #### Description
678
681
 
679
- This returns a promise that resolves with the idp access token. The promise resolves successfully only if the storage type is set to a type other than `webWorker`. Otherwise an error is thrown.
682
+ This returns a promise that resolves with the idp access token. The promise resolves successfully only if the storage type is set to a type other than `webWorker`. Otherwise, an error is thrown.
680
683
 
681
684
  #### Example
682
685
 
@@ -702,7 +705,7 @@ A Promise that resolves with the data layer object.
702
705
 
703
706
  #### Description
704
707
 
705
- This returns a promise that resolves with the data layer object. The promise resolves successfully only if the storage type is set to a type other than `webWorker`. Otherwise an error is thrown.
708
+ This returns a promise that resolves with the data layer object. The promise resolves successfully only if the storage type is set to a type other than `webWorker`. Otherwise, an error is thrown.
706
709
 
707
710
  #### Example
708
711
 
@@ -714,6 +717,35 @@ auth.getDataLayer().then((dataLayer) => {
714
717
  });
715
718
  ```
716
719
 
720
+ ---
721
+
722
+ ### getCryptoHelper
723
+
724
+ ```TypeScript
725
+ getCryptoHelper(): Promise<CryptoHelper>
726
+ ```
727
+
728
+ #### Returns
729
+
730
+ cryptoHelper : [`CryptoHelper`](#CryptoUtils)
731
+
732
+ `CryptoHelper` provides support for performing a cryptographic operation such as producing a PKCE code and verifying ID tokens.
733
+
734
+ #### Description
735
+
736
+ This method returns the `CryptoHelper` object used by the SDK to perform cryptographic operations.
737
+
738
+ #### Example
739
+
740
+ ```TypeScript
741
+ auth.getCryptoHelper().then((cryptoHelper) => {
742
+ // console.log(cryptoHelper);
743
+ }).error((error) => {
744
+ // console.error(error);
745
+ });
746
+ ```
747
+
748
+ ---
717
749
  ### refreshAccessToken
718
750
 
719
751
  ```typescript
@@ -726,22 +758,12 @@ A Promise that resolves with the [`BasicUserInfo`](#BasicUserInfo) object.
726
758
 
727
759
  #### Description
728
760
 
729
- This refreshes the access token and stores the refreshed session information in either the session or local storage as per your configuration. Note that this method cannot be used when the storage type is set to `webWorker` since the web worker automatically refreshes the token and there is no need for the developer to do it.
730
-
731
- This method also returns a Promise that resolves with an object containing the attributes mentioned in the table below.
732
- | Attribute | Description |
733
- |------------------|-------------------------------------|
734
- | `"accessToken"` | The new access token |
735
- | `"expiresIn"` | The expiry time in seconds |
736
- | `"idToken"` | The ID token |
737
- | `"refreshToken"` | The refresh token |
738
- | `"scope"` | The scope of the access token |
739
- | `"tokenType"` | The type of the token. E.g.: Bearer |
761
+ This refreshes the access token and stores the refreshed session information in either the session or local storage as per your configuration. Note that this method is not required to be used when the storage type is set to `webWorker` since the web worker automatically refreshes the token, and there is no need for the developer to do it.
740
762
 
741
763
  #### Example
742
764
 
743
765
  ```TypeScript
744
- auth.refreshToken().then((response)=>{
766
+ auth.refreshAccessToken().then((response)=>{
745
767
  // console.log(response);
746
768
  }).catch((error)=>{
747
769
  // console.error(error);
@@ -935,7 +957,7 @@ const hasParams: boolean = SPAUtils.hasAuthSearchParamsInURL();
935
957
 
936
958
  When the `responseMode` is set to `form_post`, the authorization code is sent in the body of a `POST` request as opposed to in the URL. So, the Single Page Application should have a backend to receive the authorization code and send it back to the Single Page Application.
937
959
 
938
- The backend can then inject the authorization code into a JavaSCript variable while rendering the webpage in the server side. But this results in the authorization code getting printed in the HTML of the page creating a **threat vector**.
960
+ The backend can then inject the authorization code into a JavaScript variable while rendering the webpage in the server side. But this results in the authorization code getting printed in the HTML of the page creating a **threat vector**.
939
961
 
940
962
  To address this issue, we recommend storing the authorization code in a server session variable and providing the Single Page Application a separate API endpoint to request the authorization code. The server, when the request is received, can then respond with the authorization code from the server session.
941
963
 
@@ -972,7 +994,7 @@ This table shows the extended attributes provided by the `Config` interface.
972
994
  | `requestTimeout` | Optional | `number` | 60000 (seconds) | Specifies in seconds how long a request to the web worker should wait before being timed out. |
973
995
  | `sessionRefreshInterval` | Optional | `number` | 300 (seconds) | Specifies how often the session state should be checked. To check the authentication state, the authorization endpoint is queried with the `prompt` parameter set to `none`. |
974
996
  | `checkSessionInterval` | Optional | `number` | 3 (seconds) | Specifies how often the check-session iFrame should be queried to check the session state. This is used to perform single logout. |
975
- | `enableOIDCSessionManagement` | Optional | `boolean` | false | Flag to enable OIDC Session Management |
997
+ | `enableOIDCSessionManagement` | Optional | `boolean` | false | Flag to enable OIDC Session Management. Set this flag to `true` to add single logout capabilities into your application. |
976
998
 
977
999
  #### The AuthClientConfig Interface
978
1000
 
@@ -1044,6 +1066,7 @@ This table shows the extended attributes provided by the `Config` interface.
1044
1066
  #### Custom Grant Template Tags
1045
1067
 
1046
1068
  Session information can be attached to the body of a custom-grant request using template tags. This is useful when the session information is not exposed outside the SDK but you want such information to be used in custom-grant requests. The following table lists the available template tags.
1069
+
1047
1070
  | Tag | Data |
1048
1071
  |--------------------|--------------------|
1049
1072
  | "{{token}}" | The access token. |