@asgardeo/auth-spa 0.4.1 → 0.4.4

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 (33) hide show
  1. package/README.md +24 -22
  2. package/dist/asgardeo-spa.production.esm.js +11 -11
  3. package/dist/asgardeo-spa.production.esm.js.map +1 -1
  4. package/dist/asgardeo-spa.production.js +4 -4
  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 +40 -40
  9. package/dist/polyfilled/asgardeo-spa.production.esm.js.map +1 -1
  10. package/dist/polyfilled/asgardeo-spa.production.js +4 -4
  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/clients/main-thread-client.js +2 -2
  15. package/dist/src/clients/main-thread-client.js.map +1 -1
  16. package/dist/src/helpers/authentication-helper.js +5 -5
  17. package/dist/src/helpers/authentication-helper.js.map +1 -1
  18. package/dist/src/helpers/session-management-helper.d.ts.map +1 -1
  19. package/dist/src/helpers/session-management-helper.js +0 -1
  20. package/dist/src/helpers/session-management-helper.js.map +1 -1
  21. package/dist/src/helpers/spa-helper.d.ts +2 -2
  22. package/dist/src/helpers/spa-helper.d.ts.map +1 -1
  23. package/dist/src/helpers/spa-helper.js +2 -2
  24. package/dist/src/helpers/spa-helper.js.map +1 -1
  25. package/dist/src/worker/worker-core.js +2 -2
  26. package/dist/src/worker/worker-core.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +1 -1
  29. package/src/clients/main-thread-client.ts +2 -2
  30. package/src/helpers/authentication-helper.ts +5 -5
  31. package/src/helpers/session-management-helper.ts +0 -1
  32. package/src/helpers/spa-helper.ts +7 -3
  33. package/src/worker/worker-core.ts +2 -2
package/README.md CHANGED
@@ -241,7 +241,7 @@ An instance of the `AsgardeoSPAClient`.
241
241
 
242
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.
243
243
 
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.
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.
245
245
 
246
246
  #### Example
247
247
 
@@ -270,7 +270,7 @@ initialize(config?: `AuthClientConfig<Config>`): Promise<void>;
270
270
 
271
271
  #### Description
272
272
 
273
- 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.
274
274
 
275
275
  This method takes a `config` object as the only argument. The attributes of the `config` object is as follows.
276
276
 
@@ -335,7 +335,7 @@ signIn(config?: SignInConfig, authorizationCode?: string, sessionState?: string)
335
335
 
336
336
  #### Description
337
337
 
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 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.
339
339
 
340
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.
341
341
 
@@ -401,6 +401,17 @@ The `sign-out` hook is used to fire a callback function after signing out is suc
401
401
  auth.signOut();
402
402
  ```
403
403
 
404
+ **Clearing the locally stored user session happens when a sign-out hook is registered after the user gets redirected back to the `signOutRedirectURL`.**
405
+ Therefore, the developer should ensure that a sign-out hook is registered when `signOutRedirectURL` is loaded. Refer the [example](#sign-out-hook-example)
406
+ for further details.
407
+
408
+ #### Example
409
+ ```TypeScript
410
+ // Register a sign-out hook with any callback function when signOutRedirectURL is loaded
411
+ // to clear locally stored user session
412
+ auth.on("sign-out", () => {});
413
+ ```
414
+
404
415
  ---
405
416
 
406
417
  ### httpRequest
@@ -418,6 +429,7 @@ httpRequest(config: HttpRequestConfig): Promise<HttpResponse>;
418
429
  |--------------------------|-----------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------|
419
430
  | `attachToken` | `boolean` | `true` | If set to `true`, the token will be attached to the request header. |
420
431
  | `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. |
432
+ | `shouldAttachIDPAccessToken` | `boolean` | `false` | If set to `true`, the IDP access token will be attached to the the request `Authorization` header. |
421
433
 
422
434
  #### Returns
423
435
 
@@ -425,7 +437,7 @@ A Promise that resolves with the response.
425
437
 
426
438
  #### Description
427
439
 
428
- 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.
440
+ 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.
429
441
 
430
442
  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.
431
443
 
@@ -652,7 +664,7 @@ A Promise that resolves with the access token.
652
664
 
653
665
  #### Description
654
666
 
655
- 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.
667
+ 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
668
 
657
669
  #### Example
658
670
 
@@ -678,7 +690,7 @@ A Promise that resolves with the idp access token.
678
690
 
679
691
  #### Description
680
692
 
681
- 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.
693
+ 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
694
 
683
695
  #### Example
684
696
 
@@ -704,7 +716,7 @@ A Promise that resolves with the data layer object.
704
716
 
705
717
  #### Description
706
718
 
707
- 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.
719
+ 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
720
 
709
721
  #### Example
710
722
 
@@ -757,22 +769,12 @@ A Promise that resolves with the [`BasicUserInfo`](#BasicUserInfo) object.
757
769
 
758
770
  #### Description
759
771
 
760
- 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.
761
-
762
- This method also returns a Promise that resolves with an object containing the attributes mentioned in the table below.
763
- | Attribute | Description |
764
- |------------------|-------------------------------------|
765
- | `"accessToken"` | The new access token |
766
- | `"expiresIn"` | The expiry time in seconds |
767
- | `"idToken"` | The ID token |
768
- | `"refreshToken"` | The refresh token |
769
- | `"scope"` | The scope of the access token |
770
- | `"tokenType"` | The type of the token. E.g.: Bearer |
772
+ 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.
771
773
 
772
774
  #### Example
773
775
 
774
776
  ```TypeScript
775
- auth.refreshToken().then((response)=>{
777
+ auth.refreshAccessToken().then((response)=>{
776
778
  // console.log(response);
777
779
  }).catch((error)=>{
778
780
  // console.error(error);
@@ -816,7 +818,6 @@ If you are using TypeScript, you may want to use the `Hooks` enum that consists
816
818
  **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.**
817
819
 
818
820
  #### Example
819
-
820
821
  ```TypeScript
821
822
  auth.on("sign-in", () => {
822
823
  // console.log(response);
@@ -966,7 +967,7 @@ const hasParams: boolean = SPAUtils.hasAuthSearchParamsInURL();
966
967
 
967
968
  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.
968
969
 
969
- 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**.
970
+ 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**.
970
971
 
971
972
  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.
972
973
 
@@ -1003,7 +1004,7 @@ This table shows the extended attributes provided by the `Config` interface.
1003
1004
  | `requestTimeout` | Optional | `number` | 60000 (seconds) | Specifies in seconds how long a request to the web worker should wait before being timed out. |
1004
1005
  | `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`. |
1005
1006
  | `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. |
1006
- | `enableOIDCSessionManagement` | Optional | `boolean` | false | Flag to enable OIDC Session Management |
1007
+ | `enableOIDCSessionManagement` | Optional | `boolean` | false | Flag to enable OIDC Session Management. Set this flag to `true` to add single logout capabilities into your application. |
1007
1008
 
1008
1009
  #### The AuthClientConfig Interface
1009
1010
 
@@ -1075,6 +1076,7 @@ This table shows the extended attributes provided by the `Config` interface.
1075
1076
  #### Custom Grant Template Tags
1076
1077
 
1077
1078
  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.
1079
+
1078
1080
  | Tag | Data |
1079
1081
  |--------------------|--------------------|
1080
1082
  | "{{token}}" | The access token. |