@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/src/client.ts CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  AsgardeoAuthException,
22
22
  AuthClientConfig,
23
23
  BasicUserInfo,
24
+ CryptoHelper,
24
25
  CustomGrantConfig,
25
26
  DataLayer,
26
27
  DecodedIDTokenPayload,
@@ -707,6 +708,32 @@ export class AsgardeoSPAClient {
707
708
  return this._client?.getDecodedIDToken();
708
709
  }
709
710
 
711
+ /**
712
+ * This method returns the CryptoHelper instance.
713
+ *
714
+ * @return {Promise<DecodedIdTokenPayloadInterface>} - A Promise that resolves with
715
+ * the CryptoHelper instance.
716
+ *
717
+ * @example
718
+ * ```
719
+ * auth.getCryptoHelper().then((response)=>{
720
+ * // console.log(response);
721
+ * }).catch((error)=>{
722
+ * // console.error(error);
723
+ * });
724
+ * ```
725
+ * @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getCryptoHelper
726
+ *
727
+ * @memberof AsgardeoSPAClient
728
+ *
729
+ * @preserve
730
+ */
731
+ public async getCryptoHelper(): Promise<CryptoHelper | undefined> {
732
+ await this._validateMethod();
733
+
734
+ return this._client?.getCryptoHelper();
735
+ }
736
+
710
737
  /**
711
738
  * This method return the ID token.
712
739
  *
@@ -796,7 +823,7 @@ export class AsgardeoSPAClient {
796
823
  if (this._storage && [ (Storage.WebWorker, Storage.BrowserMemory) ].includes(this._storage)) {
797
824
  return Promise.reject(
798
825
  new AsgardeoAuthException(
799
- "SPA-AUTH_CLIENT-GAT-IV01",
826
+ "SPA-AUTH_CLIENT-GIAT-IV01",
800
827
  "The access token cannot be returned.",
801
828
  "The access token cannot be returned when the storage type is set to webWorker or browserMemory."
802
829
  )
@@ -835,9 +862,9 @@ export class AsgardeoSPAClient {
835
862
  if (this._storage && [ (Storage.WebWorker, Storage.BrowserMemory) ].includes(this._storage)) {
836
863
  return Promise.reject(
837
864
  new AsgardeoAuthException(
838
- "SPA-AUTH_CLIENT-GAT-IV01",
839
- "The access token cannot be returned.",
840
- "The access token cannot be returned when the storage type is set to webWorker or browserMemory."
865
+ "SPA-AUTH_CLIENT-GDL-IV01",
866
+ "The data layer cannot be returned.",
867
+ "The data layer cannot be returned when the storage type is set to webWorker or browserMemory."
841
868
  )
842
869
  );
843
870
  }
@@ -22,6 +22,7 @@ import {
22
22
  AuthClientConfig,
23
23
  AuthenticationUtils,
24
24
  BasicUserInfo,
25
+ CryptoHelper,
25
26
  DataLayer,
26
27
  DecodedIDTokenPayload,
27
28
  FetchResponse,
@@ -96,11 +97,19 @@ export const MainThreadClient = async (
96
97
 
97
98
  const attachToken = async (request: HttpRequestConfig): Promise<void> => {
98
99
  const requestConfig = { attachToken: true, ...request };
100
+
99
101
  if (requestConfig.attachToken) {
100
- request.headers = {
101
- ...request.headers,
102
- Authorization: `Bearer ${ await _authenticationHelper.getAccessToken() }`
103
- };
102
+ if(requestConfig.shouldAttachIDPAccessToken) {
103
+ request.headers = {
104
+ ...request.headers,
105
+ Authorization: `Bearer ${ await _authenticationHelper.getIDPAccessToken() }`
106
+ };
107
+ } else {
108
+ request.headers = {
109
+ ...request.headers,
110
+ Authorization: `Bearer ${ await _authenticationHelper.getAccessToken() }`
111
+ };
112
+ }
104
113
  }
105
114
  }
106
115
 
@@ -356,6 +365,10 @@ export const MainThreadClient = async (
356
365
  return _authenticationHelper.getDecodedIDToken();
357
366
  };
358
367
 
368
+ const getCryptoHelper = async (): Promise<CryptoHelper> => {
369
+ return _authenticationHelper.getCryptoHelper();
370
+ };
371
+
359
372
  const getIDToken = async (): Promise<string> => {
360
373
  return _authenticationHelper.getIDToken();
361
374
  };
@@ -403,6 +416,7 @@ export const MainThreadClient = async (
403
416
  enableHttpHandler,
404
417
  getAccessToken,
405
418
  getBasicUserInfo,
419
+ getCryptoHelper,
406
420
  getDataLayer,
407
421
  getDecodedIDToken,
408
422
  getHttpClient,
@@ -23,6 +23,7 @@ import {
23
23
  AuthClientConfig,
24
24
  AuthenticationUtils,
25
25
  BasicUserInfo,
26
+ CryptoHelper,
26
27
  CustomGrantConfig,
27
28
  DecodedIDTokenPayload,
28
29
  FetchResponse,
@@ -39,6 +40,8 @@ import {
39
40
  GET_AUTH_URL,
40
41
  GET_BASIC_USER_INFO,
41
42
  GET_CONFIG_DATA,
43
+ GET_CRYPTO_HELPER,
44
+ GET_DECODED_IDP_ID_TOKEN,
42
45
  GET_DECODED_ID_TOKEN,
43
46
  GET_ID_TOKEN,
44
47
  GET_OIDC_SERVICE_ENDPOINTS,
@@ -691,6 +694,34 @@ export const WebWorkerClient = async (
691
694
  });
692
695
  };
693
696
 
697
+ const getDecodedIDPIDToken = (): Promise<DecodedIDTokenPayload> => {
698
+ const message: Message<null> = {
699
+ type: GET_DECODED_IDP_ID_TOKEN
700
+ };
701
+
702
+ return communicate<null, DecodedIDTokenPayload>(message)
703
+ .then((response) => {
704
+ return Promise.resolve(response);
705
+ })
706
+ .catch((error) => {
707
+ return Promise.reject(error);
708
+ });
709
+ };
710
+
711
+ const getCryptoHelper = (): Promise<CryptoHelper> => {
712
+ const message: Message<null> = {
713
+ type: GET_CRYPTO_HELPER
714
+ };
715
+
716
+ return communicate<null, CryptoHelper>(message)
717
+ .then((response) => {
718
+ return Promise.resolve(response);
719
+ })
720
+ .catch((error) => {
721
+ return Promise.reject(error);
722
+ });
723
+ };
724
+
694
725
  const getIDToken = (): Promise<string> => {
695
726
  const message: Message<null> = {
696
727
  type: GET_ID_TOKEN
@@ -783,6 +814,8 @@ export const WebWorkerClient = async (
783
814
  disableHttpHandler,
784
815
  enableHttpHandler,
785
816
  getBasicUserInfo,
817
+ getCryptoHelper,
818
+ getDecodedIDPIDToken,
786
819
  getDecodedIDToken,
787
820
  getIDToken,
788
821
  getOIDCServiceEndpoints,
@@ -32,6 +32,8 @@ export const REQUEST_FINISH = "request-finish";
32
32
  export const GET_OIDC_SERVICE_ENDPOINTS = "get-oidc-service-endpoints";
33
33
  export const GET_BASIC_USER_INFO = "get-basic-user-info";
34
34
  export const GET_DECODED_ID_TOKEN = "get-decoded-id-token";
35
+ export const GET_DECODED_IDP_ID_TOKEN = "get-decoded-idp-id-token";
36
+ export const GET_CRYPTO_HELPER = "get-crypto-helper"
35
37
  export const ENABLE_HTTP_HANDLER = "enable_http_handler";
36
38
  export const DISABLE_HTTP_HANDLER = "disable_http_handler";
37
39
  export const GET_AUTH_URL = "get_auth_url";
@@ -22,6 +22,7 @@ import {
22
22
  AuthClientConfig,
23
23
  AuthenticationUtils,
24
24
  BasicUserInfo,
25
+ CryptoHelper,
25
26
  CustomGrantConfig,
26
27
  DataLayer,
27
28
  DecodedIDTokenPayload,
@@ -609,6 +610,14 @@ export class AuthenticationHelper<
609
610
  return this._authenticationClient.getDecodedIDToken();
610
611
  }
611
612
 
613
+ public async getDecodedIDPIDToken(): Promise<DecodedIDTokenPayload> {
614
+ return this._authenticationClient.getDecodedIDToken();
615
+ }
616
+
617
+ public async getCryptoHelper(): Promise<CryptoHelper> {
618
+ return this._authenticationClient.getCryptoHelper();
619
+ }
620
+
612
621
  public async getIDToken(): Promise<string> {
613
622
  return this._authenticationClient.getIDToken();
614
623
  }
@@ -621,6 +630,10 @@ export class AuthenticationHelper<
621
630
  return this._authenticationClient.getAccessToken();
622
631
  }
623
632
 
633
+ public async getIDPAccessToken(): Promise<string> {
634
+ return (await this._dataLayer.getSessionData())?.access_token;
635
+ }
636
+
624
637
  public getDataLayer(): DataLayer<T> {
625
638
  return this._dataLayer;
626
639
  }
@@ -98,7 +98,6 @@ export const SessionManagementHelper = (() => {
98
98
  const opIframe: HTMLIFrameElement
99
99
  = rpIFrame?.contentDocument?.getElementById(OP_IFRAME) as HTMLIFrameElement;
100
100
  opIframe.src = _checkSessionEndpoint + "?client_id=" + _clientID + "&redirect_uri=" + _redirectURL;
101
- await checkSession();
102
101
 
103
102
  _checkSessionIntervalTimeout = setInterval(checkSession, _interval * 1000) as unknown as number;
104
103
 
@@ -19,6 +19,7 @@
19
19
  import {
20
20
  AuthClientConfig,
21
21
  BasicUserInfo,
22
+ CryptoHelper,
22
23
  CustomGrantConfig,
23
24
  DataLayer,
24
25
  DecodedIDTokenPayload,
@@ -57,6 +58,7 @@ export interface MainThreadClientInterface {
57
58
  revokeAccessToken(): Promise<boolean>;
58
59
  getBasicUserInfo(): Promise<BasicUserInfo>;
59
60
  getDecodedIDToken(): Promise<DecodedIDTokenPayload>;
61
+ getCryptoHelper(): Promise<CryptoHelper>;
60
62
  getIDToken(): Promise<string>;
61
63
  getOIDCServiceEndpoints(): Promise<OIDCEndpoints>;
62
64
  getAccessToken(): Promise<string>;
@@ -84,6 +86,8 @@ export interface WebWorkerClientInterface {
84
86
  getOIDCServiceEndpoints(): Promise<OIDCEndpoints>;
85
87
  getBasicUserInfo(): Promise<BasicUserInfo>;
86
88
  getDecodedIDToken(): Promise<DecodedIDTokenPayload>;
89
+ getDecodedIDPIDToken(): Promise<DecodedIDTokenPayload>;
90
+ getCryptoHelper(): Promise<CryptoHelper>;
87
91
  getIDToken(): Promise<string>;
88
92
  isAuthenticated(): Promise<boolean>;
89
93
  setHttpRequestSuccessCallback(callback: (response: HttpResponse) => void): void;
@@ -29,6 +29,7 @@ export interface HttpClient {
29
29
  export interface HttpRequestConfig extends AxiosRequestConfig {
30
30
  attachToken?: boolean;
31
31
  shouldEncodeToFormData?: boolean;
32
+ shouldAttachIDPAccessToken?: boolean;
32
33
  startTimeInMs?: number
33
34
  }
34
35
 
@@ -26,6 +26,8 @@ import {
26
26
  GET_AUTH_URL,
27
27
  GET_BASIC_USER_INFO,
28
28
  GET_CONFIG_DATA,
29
+ GET_CRYPTO_HELPER,
30
+ GET_DECODED_IDP_ID_TOKEN,
29
31
  GET_DECODED_ID_TOKEN,
30
32
  GET_ID_TOKEN,
31
33
  GET_OIDC_SERVICE_ENDPOINTS,
@@ -86,6 +88,8 @@ export type MessageType =
86
88
  | typeof GET_OIDC_SERVICE_ENDPOINTS
87
89
  | typeof GET_BASIC_USER_INFO
88
90
  | typeof GET_DECODED_ID_TOKEN
91
+ | typeof GET_CRYPTO_HELPER
92
+ | typeof GET_DECODED_IDP_ID_TOKEN
89
93
  | typeof ENABLE_HTTP_HANDLER
90
94
  | typeof DISABLE_HTTP_HANDLER
91
95
  | typeof GET_AUTH_URL
@@ -20,6 +20,7 @@ import {
20
20
  AuthClientConfig,
21
21
  AuthorizationURLParams,
22
22
  BasicUserInfo,
23
+ CryptoHelper,
23
24
  CustomGrantConfig,
24
25
  DecodedIDTokenPayload,
25
26
  FetchResponse,
@@ -58,6 +59,8 @@ export interface WebWorkerCoreInterface {
58
59
  revokeAccessToken(): Promise<boolean>;
59
60
  getBasicUserInfo(): Promise<BasicUserInfo>;
60
61
  getDecodedIDToken(): Promise<DecodedIDTokenPayload>;
62
+ getDecodedIDPIDToken(): Promise<DecodedIDTokenPayload>;
63
+ getCryptoHelper(): Promise<CryptoHelper>;
61
64
  getIDToken(): Promise<string>;
62
65
  getOIDCServiceEndpoints(): Promise<OIDCEndpoints>;
63
66
  getAccessToken(): Promise<string>;
package/src/public-api.ts CHANGED
@@ -31,6 +31,13 @@ export * from "./constants/hooks";
31
31
 
32
32
  export * from "@asgardeo/auth-js";
33
33
 
34
+ // clients
35
+ export * from "./clients/main-thread-client";
36
+ export * from "./clients/web-worker-client";
37
+
38
+ // models
39
+ export * from "./models/request-custom-grant";
40
+
34
41
  // helpers
35
42
  export * from "./helpers/authentication-helper";
36
43
  export * from "./helpers/spa-helper";
@@ -21,6 +21,7 @@ import {
21
21
  AuthClientConfig,
22
22
  AuthorizationURLParams,
23
23
  BasicUserInfo,
24
+ CryptoHelper,
24
25
  CustomGrantConfig,
25
26
  DecodedIDTokenPayload,
26
27
  FetchResponse,
@@ -65,10 +66,17 @@ export const WebWorkerCore = async (
65
66
  const attachToken = async (request: HttpRequestConfig): Promise<void> => {
66
67
  const requestConfig = { attachToken: true, ...request };
67
68
  if (requestConfig.attachToken) {
68
- request.headers = {
69
- ...request.headers,
70
- Authorization: `Bearer ${ await _authenticationHelper.getAccessToken() }`
71
- };
69
+ if(requestConfig.shouldAttachIDPAccessToken) {
70
+ request.headers = {
71
+ ...request.headers,
72
+ Authorization: `Bearer ${ await _authenticationHelper.getIDPAccessToken() }`
73
+ };
74
+ } else {
75
+ request.headers = {
76
+ ...request.headers,
77
+ Authorization: `Bearer ${ await _authenticationHelper.getAccessToken() }`
78
+ };
79
+ }
72
80
  }
73
81
  };
74
82
 
@@ -186,6 +194,14 @@ export const WebWorkerCore = async (
186
194
  return _authenticationHelper.getDecodedIDToken();
187
195
  };
188
196
 
197
+ const getCryptoHelper = async (): Promise<CryptoHelper> => {
198
+ return _authenticationHelper.getCryptoHelper();
199
+ };
200
+
201
+ const getDecodedIDPIDToken = async (): Promise<DecodedIDTokenPayload> => {
202
+ return _authenticationHelper.getDecodedIDPIDToken();
203
+ };
204
+
189
205
  const getIDToken = async (): Promise<string> => {
190
206
  return _authenticationHelper.getIDToken();
191
207
  };
@@ -224,6 +240,8 @@ export const WebWorkerCore = async (
224
240
  getAuthorizationURL,
225
241
  getBasicUserInfo,
226
242
  getConfigData,
243
+ getCryptoHelper,
244
+ getDecodedIDPIDToken,
227
245
  getDecodedIDToken,
228
246
  getIDToken,
229
247
  getOIDCServiceEndpoints,
@@ -29,6 +29,7 @@ import {
29
29
  GET_AUTH_URL,
30
30
  GET_BASIC_USER_INFO,
31
31
  GET_CONFIG_DATA,
32
+ GET_CRYPTO_HELPER,
32
33
  GET_DECODED_ID_TOKEN,
33
34
  GET_ID_TOKEN,
34
35
  GET_OIDC_SERVICE_ENDPOINTS,
@@ -195,6 +196,14 @@ export const workerReceiver = (
195
196
  port.postMessage(MessageUtils.generateFailureMessage(error));
196
197
  }
197
198
 
199
+ break;
200
+ case GET_CRYPTO_HELPER:
201
+ try {
202
+ port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getCryptoHelper()));
203
+ } catch (error) {
204
+ port.postMessage(MessageUtils.generateFailureMessage(error));
205
+ }
206
+
198
207
  break;
199
208
  case GET_ID_TOKEN:
200
209
  try {