@axa-fr/oidc-client 7.29.8 → 7.30.0

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 (71) hide show
  1. package/README.md +174 -0
  2. package/dist/events.d.ts +3 -0
  3. package/dist/events.d.ts.map +1 -1
  4. package/dist/fetch.d.ts +2 -2
  5. package/dist/fetch.d.ts.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1339 -871
  9. package/dist/index.umd.cjs +2 -2
  10. package/dist/initSession.d.ts +2 -0
  11. package/dist/initSession.d.ts.map +1 -1
  12. package/dist/initWorker.d.ts +1 -25
  13. package/dist/initWorker.d.ts.map +1 -1
  14. package/dist/jwt.d.ts.map +1 -1
  15. package/dist/legacyCompatibility.spec.d.ts +2 -0
  16. package/dist/legacyCompatibility.spec.d.ts.map +1 -0
  17. package/dist/login.d.ts +2 -1
  18. package/dist/login.d.ts.map +1 -1
  19. package/dist/logout.d.ts.map +1 -1
  20. package/dist/node_modules/@axa-fr/oidc-client-service-worker/dist/OidcServiceWorker.js +1049 -0
  21. package/dist/node_modules/@axa-fr/oidc-client-service-worker/dist/OidcTrustedDomains.js +31 -0
  22. package/dist/oidc.d.ts +6 -1
  23. package/dist/oidc.d.ts.map +1 -1
  24. package/dist/oidcClient.d.ts +13 -2
  25. package/dist/oidcClient.d.ts.map +1 -1
  26. package/dist/oidcError.d.ts +5 -0
  27. package/dist/oidcError.d.ts.map +1 -1
  28. package/dist/parseTokens.d.ts +10 -0
  29. package/dist/parseTokens.d.ts.map +1 -1
  30. package/dist/protocol.d.ts +7 -1
  31. package/dist/protocol.d.ts.map +1 -1
  32. package/dist/renewTokens.d.ts +0 -6
  33. package/dist/renewTokens.d.ts.map +1 -1
  34. package/dist/requests.d.ts +3 -3
  35. package/dist/requests.d.ts.map +1 -1
  36. package/dist/resourceParameters.d.ts +9 -0
  37. package/dist/resourceParameters.d.ts.map +1 -0
  38. package/dist/resourceTokens.d.ts +34 -0
  39. package/dist/resourceTokens.d.ts.map +1 -0
  40. package/dist/resourceTokens.spec.d.ts +2 -0
  41. package/dist/resourceTokens.spec.d.ts.map +1 -0
  42. package/dist/silentLogin.d.ts +2 -1
  43. package/dist/silentLogin.d.ts.map +1 -1
  44. package/dist/types.d.ts +28 -0
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/version.d.ts +1 -1
  47. package/package.json +3 -3
  48. package/src/events.ts +3 -0
  49. package/src/fetch.ts +115 -15
  50. package/src/index.ts +4 -0
  51. package/src/initSession.ts +9 -0
  52. package/src/initWorker.ts +65 -13
  53. package/src/jwt.spec.ts +17 -0
  54. package/src/jwt.ts +4 -1
  55. package/src/legacyCompatibility.spec.ts +142 -0
  56. package/src/login.ts +91 -29
  57. package/src/logout.ts +36 -0
  58. package/src/oidc.ts +71 -20
  59. package/src/oidcClient.ts +48 -3
  60. package/src/oidcError.ts +7 -0
  61. package/src/parseTokens.ts +14 -1
  62. package/src/protocol.ts +16 -1
  63. package/src/renewTokens.ts +19 -8
  64. package/src/requests.ts +13 -11
  65. package/src/resourceParameters.ts +85 -0
  66. package/src/resourceTokens.spec.ts +1271 -0
  67. package/src/resourceTokens.ts +708 -0
  68. package/src/silentLogin.spec.ts +87 -1
  69. package/src/silentLogin.ts +24 -22
  70. package/src/types.ts +34 -0
  71. package/src/version.ts +1 -1
package/src/requests.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  PushedAuthorizationRequestError,
8
8
  PushedAuthorizationRequestErrorCode,
9
9
  } from './pushedAuthorizationRequestError.js';
10
- import { Fetch, StringMap } from './types.js';
10
+ import { Fetch, OAuthParameters, StringMap } from './types.js';
11
11
 
12
12
  const oneHourSecond = 60 * 60;
13
13
  export const fetchFromIssuer =
@@ -69,10 +69,14 @@ export const TOKEN_TYPE = {
69
69
  access_token: 'access_token',
70
70
  };
71
71
 
72
- const encodeFormBody = (details: StringMap): string => {
72
+ const encodeFormBody = (details: OAuthParameters): string => {
73
73
  const formBody: string[] = [];
74
74
  for (const property in details) {
75
- formBody.push(`${encodeURIComponent(property)}=${encodeURIComponent(details[property])}`);
75
+ const value = details[property];
76
+ const values = Array.isArray(value) ? value : [String(value)];
77
+ for (const item of values) {
78
+ formBody.push(`${encodeURIComponent(property)}=${encodeURIComponent(item)}`);
79
+ }
76
80
  }
77
81
  return formBody.join('&');
78
82
  };
@@ -153,7 +157,7 @@ export const performPushedAuthorizationRequestAsync =
153
157
  (fetch: Fetch) =>
154
158
  async (
155
159
  url: string,
156
- details: StringMap,
160
+ details: OAuthParameters,
157
161
  timeoutMs = 10000,
158
162
  ): Promise<PushedAuthorizationRequestResponse> => {
159
163
  if (details.request_uri !== undefined) {
@@ -291,7 +295,7 @@ export const performAuthorizationRequestAsync =
291
295
  (storage: any, oidcLocation: ILOidcLocation) =>
292
296
  async (
293
297
  url,
294
- extras: StringMap,
298
+ extras: OAuthParameters,
295
299
  pushedAuthorizationRequest?: {
296
300
  endpoint: string;
297
301
  fetch: Fetch;
@@ -311,7 +315,7 @@ export const performAuthorizationRequestAsync =
311
315
  pushedAuthorizationRequest.fetch,
312
316
  )(pushedAuthorizationRequest.endpoint, extras, pushedAuthorizationRequest.timeoutMs);
313
317
  oidcLocation.open(
314
- `${url}?client_id=${encodeURIComponent(extras.client_id)}&request_uri=${encodeURIComponent(
318
+ `${url}?client_id=${encodeURIComponent(String(extras.client_id))}&request_uri=${encodeURIComponent(
315
319
  response.request_uri,
316
320
  )}`,
317
321
  );
@@ -321,12 +325,10 @@ export const performAuthorizationRequestAsync =
321
325
  let queryString = '';
322
326
  if (extras) {
323
327
  for (const [key, value] of Object.entries(extras)) {
324
- if (queryString === '') {
325
- queryString += '?';
326
- } else {
327
- queryString += '&';
328
+ for (const item of Array.isArray(value) ? value : [String(value)]) {
329
+ queryString += queryString === '' ? '?' : '&';
330
+ queryString += `${key}=${encodeURIComponent(item)}`;
328
331
  }
329
- queryString += `${key}=${encodeURIComponent(value)}`;
330
332
  }
331
333
  }
332
334
  oidcLocation.open(`${url}${queryString}`);
@@ -0,0 +1,85 @@
1
+ import { OidcError, OidcErrorCode } from './oidcError';
2
+ import {
3
+ getResourceConfiguration,
4
+ getResourceContextName,
5
+ validateResourceIdentifier,
6
+ } from './protocol';
7
+ import { getParseQueryStringFromLocation } from './route-utils';
8
+ import type { OAuthParameters, OidcConfiguration } from './types';
9
+
10
+ export const RESOURCE_LOGIN_PARAMETER = '_oidc_resource';
11
+ const transactionPrefix = 'oidc.resource_transaction.';
12
+
13
+ export const resourceContextName = (name: string, resource?: string): string =>
14
+ resource === undefined ? name : getResourceContextName(name, resource);
15
+
16
+ export const applyResourceParameters = (
17
+ parameters: OAuthParameters,
18
+ configuration: OidcConfiguration,
19
+ resource?: string,
20
+ ): OAuthParameters => {
21
+ const selected = resource ?? configuration.resource;
22
+ if (selected === undefined) return parameters;
23
+ const resources = typeof selected === 'string' ? [selected] : selected;
24
+ if (resources.length === 0) {
25
+ throw new OidcError(OidcErrorCode.INVALID_RESOURCE, 'At least one resource is required.', {
26
+ phase: 'login',
27
+ retryable: false,
28
+ });
29
+ }
30
+ for (const value of resources) {
31
+ validateResourceIdentifier(value);
32
+ if (configuration.resources) getResourceConfiguration(configuration.resources, value);
33
+ }
34
+ const supplied = parameters.resource;
35
+ if (
36
+ supplied !== undefined &&
37
+ JSON.stringify(typeof supplied === 'string' ? [supplied] : supplied) !==
38
+ JSON.stringify(resources)
39
+ ) {
40
+ throw new OidcError(
41
+ OidcErrorCode.INVALID_RESOURCE,
42
+ 'Resource extras conflict with the selected resource.',
43
+ {
44
+ phase: 'login',
45
+ retryable: false,
46
+ },
47
+ );
48
+ }
49
+ return { ...parameters, resource: selected };
50
+ };
51
+
52
+ export const rememberResourceTransaction = (
53
+ configurationName: string,
54
+ state: string,
55
+ resource: string,
56
+ ): void => {
57
+ sessionStorage.setItem(`${transactionPrefix}${configurationName}.${state}`, resource);
58
+ };
59
+
60
+ export const getCallbackResource = (
61
+ configurationName: string,
62
+ href: string,
63
+ ): string | undefined => {
64
+ const { state } = getParseQueryStringFromLocation(href);
65
+ return state
66
+ ? (sessionStorage.getItem(`${transactionPrefix}${configurationName}.${state}`) ?? undefined)
67
+ : undefined;
68
+ };
69
+
70
+ export const clearResourceTransaction = (configurationName: string, href: string): void => {
71
+ const { state } = getParseQueryStringFromLocation(href);
72
+ if (state) sessionStorage.removeItem(`${transactionPrefix}${configurationName}.${state}`);
73
+ };
74
+
75
+ export const cancelResourceTransactions = (configurationName: string, resource?: string): void => {
76
+ const prefix = `${transactionPrefix}${configurationName}.`;
77
+ for (const key of Object.keys(sessionStorage)) {
78
+ if (
79
+ key.startsWith(prefix) &&
80
+ (resource === undefined || sessionStorage.getItem(key) === resource)
81
+ ) {
82
+ sessionStorage.removeItem(key);
83
+ }
84
+ }
85
+ };