@toa.io/extensions.exposition 1.0.0-alpha.149 → 1.0.0-alpha.150

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 (96) hide show
  1. package/components/identity.bans/operations/tsconfig.tsbuildinfo +1 -1
  2. package/components/identity.basic/operations/tsconfig.tsbuildinfo +1 -1
  3. package/components/identity.federation/manifest.toa.yaml +22 -25
  4. package/components/identity.federation/operations/authenticate.d.ts +6 -4
  5. package/components/identity.federation/operations/authenticate.js +18 -8
  6. package/components/identity.federation/operations/authenticate.js.map +1 -1
  7. package/components/identity.federation/operations/decode.d.ts +3 -2
  8. package/components/identity.federation/operations/decode.js +9 -29
  9. package/components/identity.federation/operations/decode.js.map +1 -1
  10. package/components/identity.federation/operations/incept.d.ts +3 -2
  11. package/components/identity.federation/operations/incept.js +15 -5
  12. package/components/identity.federation/operations/incept.js.map +1 -1
  13. package/components/identity.federation/operations/lib/Configuration.d.ts +39 -0
  14. package/components/identity.federation/operations/lib/Configuration.js +3 -0
  15. package/components/identity.federation/operations/lib/Configuration.js.map +1 -0
  16. package/components/identity.federation/operations/lib/Ctx.d.ts +7 -0
  17. package/components/identity.federation/operations/lib/Ctx.js +3 -0
  18. package/components/identity.federation/operations/lib/Ctx.js.map +1 -0
  19. package/components/identity.federation/operations/lib/Payload.d.ts +5 -0
  20. package/components/identity.federation/operations/lib/Payload.js +3 -0
  21. package/components/identity.federation/operations/lib/Payload.js.map +1 -0
  22. package/components/identity.federation/operations/lib/decode.d.ts +3 -0
  23. package/components/identity.federation/operations/lib/decode.js +59 -0
  24. package/components/identity.federation/operations/lib/decode.js.map +1 -0
  25. package/components/identity.federation/operations/lib/discovery.d.ts +4 -0
  26. package/components/identity.federation/operations/lib/{assertions-as-values.js → discovery.js} +23 -21
  27. package/components/identity.federation/operations/lib/discovery.js.map +1 -0
  28. package/components/identity.federation/operations/lib/errors.d.ts +11 -0
  29. package/components/identity.federation/operations/lib/errors.js +15 -0
  30. package/components/identity.federation/operations/lib/errors.js.map +1 -0
  31. package/components/identity.federation/operations/lib/exchange.d.ts +3 -0
  32. package/components/identity.federation/operations/lib/exchange.js +107 -0
  33. package/components/identity.federation/operations/lib/exchange.js.map +1 -0
  34. package/components/identity.federation/operations/lib/index.d.ts +3 -0
  35. package/components/identity.federation/operations/lib/index.js +8 -0
  36. package/components/identity.federation/operations/lib/index.js.map +1 -0
  37. package/components/identity.federation/operations/tsconfig.tsbuildinfo +1 -1
  38. package/components/identity.federation/operations/types/Scheme.d.ts +1 -0
  39. package/components/identity.federation/operations/types/Scheme.js +3 -0
  40. package/components/identity.federation/operations/types/Scheme.js.map +1 -0
  41. package/components/identity.federation/operations/types/configuration.d.ts +9 -4
  42. package/components/identity.federation/operations/types/context.d.ts +2 -18
  43. package/components/identity.federation/operations/types/index.d.ts +1 -0
  44. package/components/identity.federation/operations/types/index.js +1 -0
  45. package/components/identity.federation/operations/types/index.js.map +1 -1
  46. package/components/identity.federation/source/authenticate.ts +27 -11
  47. package/components/identity.federation/source/decode.ts +9 -7
  48. package/components/identity.federation/source/incept.ts +19 -7
  49. package/components/identity.federation/source/lib/Configuration.ts +39 -0
  50. package/components/identity.federation/source/lib/Ctx.ts +8 -0
  51. package/components/identity.federation/source/lib/Payload.ts +6 -0
  52. package/components/identity.federation/source/lib/decode.ts +48 -0
  53. package/components/identity.federation/source/lib/discovery.ts +30 -0
  54. package/components/identity.federation/source/lib/errors.ts +12 -0
  55. package/components/identity.federation/source/lib/exchange.ts +116 -0
  56. package/components/identity.federation/source/lib/index.ts +3 -0
  57. package/components/identity.federation/source/types/Scheme.ts +1 -0
  58. package/components/identity.federation/source/types/configuration.ts +9 -4
  59. package/components/identity.federation/source/types/context.ts +3 -20
  60. package/components/identity.federation/source/types/index.ts +1 -0
  61. package/components/identity.keys/operations/tsconfig.tsbuildinfo +1 -1
  62. package/components/identity.otp/operations/tsconfig.tsbuildinfo +1 -1
  63. package/components/identity.passkeys/operations/tsconfig.tsbuildinfo +1 -1
  64. package/components/identity.roles/operations/tsconfig.tsbuildinfo +1 -1
  65. package/components/identity.tokens/operations/tsconfig.tsbuildinfo +1 -1
  66. package/documentation/identity.md +41 -2
  67. package/features/auth.claims.feature +0 -1
  68. package/features/authorities.federation.feature +0 -1
  69. package/features/identity.federation.feature +53 -34
  70. package/features/map.feature +1 -2
  71. package/features/steps/{IdP.ts → IDP.ts} +141 -23
  72. package/package.json +10 -12
  73. package/source/HTTP/Server.ts +3 -2
  74. package/source/directives/auth/Authorization.ts +1 -0
  75. package/source/directives/auth/schemes.ts +1 -0
  76. package/source/directives/auth/types.ts +1 -1
  77. package/transpiled/HTTP/Server.js +3 -2
  78. package/transpiled/HTTP/Server.js.map +1 -1
  79. package/transpiled/directives/auth/Authorization.js +1 -0
  80. package/transpiled/directives/auth/Authorization.js.map +1 -1
  81. package/transpiled/directives/auth/schemes.js +1 -0
  82. package/transpiled/directives/auth/schemes.js.map +1 -1
  83. package/transpiled/directives/auth/types.d.ts +1 -1
  84. package/transpiled/tsconfig.tsbuildinfo +1 -1
  85. package/components/identity.federation/operations/lib/assertions-as-values.d.ts +0 -4
  86. package/components/identity.federation/operations/lib/assertions-as-values.js.map +0 -1
  87. package/components/identity.federation/operations/lib/get.d.ts +0 -1
  88. package/components/identity.federation/operations/lib/get.js +0 -64
  89. package/components/identity.federation/operations/lib/get.js.map +0 -1
  90. package/components/identity.federation/operations/lib/jwt.d.ts +0 -20
  91. package/components/identity.federation/operations/lib/jwt.js +0 -152
  92. package/components/identity.federation/operations/lib/jwt.js.map +0 -1
  93. package/components/identity.federation/source/lib/assertions-as-values.ts +0 -22
  94. package/components/identity.federation/source/lib/get.ts +0 -82
  95. package/components/identity.federation/source/lib/jwt.test.ts +0 -179
  96. package/components/identity.federation/source/lib/jwt.ts +0 -198
@@ -41,6 +41,7 @@ operations:
41
41
  input:
42
42
  authority*: string
43
43
  credentials*: string
44
+ scheme: [bearer, code]
44
45
  output:
45
46
  properties:
46
47
  identity:
@@ -90,30 +91,29 @@ configuration:
90
91
  additionalProperties: false
91
92
  properties:
92
93
  iss:
93
- description: Allowed origins for a token `iss` field
94
+ description: Allowed values for a token `iss` field
94
95
  type: string
95
96
  format: uri
96
97
  aud:
97
- description: Acceptable `aud` value(s)
98
- type: array
99
- items:
100
- type: string
101
- uniqueItems: true
102
- minItems: 1
103
- secrets:
104
- description: Symmetric encryption secrets
105
- type: object
106
- patternProperties:
107
- ^HS\d{3}$:
108
- type: object
109
- patternProperties:
110
- ^\w+$:
111
- type: string
112
- minProperties: 1
113
- additionalProperties: false
114
- minProperties: 1
98
+ description: Acceptable `aud` value(s). Required for Authorization Code Flow.
99
+ anyOf:
100
+ - type: string
101
+ - type: array
102
+ items: { type: string }
103
+ uniqueItems: true
104
+ minItems: 1
105
+ signature:
106
+ properties:
107
+ iss: { type: string }
108
+ kid: { type: string }
109
+ key: { type: string }
110
+ required: [iss, kid, key]
111
+ secret:
112
+ description: Client secret for the Identity Provider. Required for Authorization Code Flow.
113
+ type: string
115
114
  required:
116
115
  - iss
116
+ default: []
117
117
  principal:
118
118
  title: Principal
119
119
  description: Subject that will be assigned the `system` Role
@@ -128,13 +128,10 @@ configuration:
128
128
  - iss
129
129
  - sub
130
130
  additionalProperties: false
131
- implicit:
132
- title: Implicitly create Identity
133
- description: |
134
- Enabling this will make Identity inception impossible.
135
- DEPRECATED: use `auth:assert`
131
+ assert:
132
+ title: Implicitly incept Identity for new credentials
136
133
  type: boolean
137
- default: false
134
+ default: true
138
135
  additionalProperties: false
139
136
 
140
137
  stash: ~
@@ -1,14 +1,16 @@
1
- import { type Maybe } from '@toa.io/types';
2
- import type { Context, IdToken } from './types';
3
- export declare const computation: (args_0: Input, context: Context) => Promise<Error | Promise<Maybe<Output>>>;
1
+ import type { JWTPayload } from 'jose';
2
+ import type { Maybe } from '@toa.io/types';
3
+ import type { Context, Scheme } from './types';
4
+ export declare function effect({ scheme, authority, credentials }: Input, context: Context): Promise<Maybe<Output>>;
4
5
  interface Input {
6
+ scheme: Scheme;
5
7
  authority: string;
6
8
  credentials: string;
7
9
  }
8
10
  interface Output {
9
11
  identity: {
10
12
  id: string;
11
- claims: Pick<IdToken, 'iss' | 'sub' | 'aud'>;
13
+ claims: JWTPayload;
12
14
  };
13
15
  }
14
16
  export {};
@@ -1,21 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computation = void 0;
3
+ exports.effect = void 0;
4
4
  const error_value_1 = require("error-value");
5
- const assertions_as_values_js_1 = require("./lib/assertions-as-values.js");
6
- const jwt_1 = require("./lib/jwt");
7
- async function authenticate({ authority, credentials }, context) {
8
- const claims = await (0, jwt_1.decode)(credentials, context.configuration.trust, context.stash);
5
+ const lib_1 = require("./lib");
6
+ async function effect({ scheme, authority, credentials }, context) {
7
+ context.logs.debug('Authenticating', { scheme, authority, credentials });
8
+ const ctx = {
9
+ trust: context.configuration.trust,
10
+ stash: context.stash,
11
+ logs: context.logs
12
+ };
13
+ const claims = scheme === 'bearer'
14
+ ? await (0, lib_1.decode)(credentials, ctx)
15
+ : await (0, lib_1.exchange)(credentials, ctx);
16
+ if (claims instanceof Error)
17
+ return claims;
9
18
  const { iss, sub } = claims;
10
19
  context.logs.debug('Token claims', claims);
11
- const identity = context.configuration.implicit
20
+ const identity = context.configuration.assert !== false
12
21
  ? await context.local.ensure({ entity: { authority, iss, sub } })
13
22
  : await context.local.observe({ query: { criteria: `authority==${authority};iss==${iss};sub==${sub}` } });
14
23
  if (identity === null)
15
24
  return ERR_NOT_FOUND;
25
+ if (identity instanceof Error)
26
+ return identity;
16
27
  return { identity: { id: identity.id, claims } };
17
28
  }
29
+ exports.effect = effect;
18
30
  const ERR_NOT_FOUND = new error_value_1.Err('NOT_FOUND');
19
- // Exporting as a function returning assertion errors as values
20
- exports.computation = (0, assertions_as_values_js_1.assertionsAsValues)(authenticate);
21
31
  //# sourceMappingURL=authenticate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../source/authenticate.ts"],"names":[],"mappings":";;;AACA,6CAAiC;AACjC,2EAAkE;AAClE,mCAAkC;AAGlC,KAAK,UAAU,YAAY,CAAE,EAAE,SAAS,EAAE,WAAW,EAAS,EAAE,OAAgB;IAC9E,MAAM,MAAM,GAAG,MAAM,IAAA,YAAM,EAAC,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IACpF,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAA;IAE3B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;IAE1C,MAAM,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,QAAQ;QAC7C,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC;QACjE,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,cAAc,SAAS,SAAS,GAAG,SAAS,GAAG,EAAE,EAAE,EAAE,CAAC,CAAA;IAE3G,IAAI,QAAQ,KAAK,IAAI;QACnB,OAAO,aAAa,CAAA;IAEtB,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAA;AAClD,CAAC;AAED,MAAM,aAAa,GAAG,IAAI,iBAAG,CAAC,WAAW,CAAC,CAAA;AAE1C,+DAA+D;AAClD,QAAA,WAAW,GAAG,IAAA,4CAAkB,EAAC,YAAY,CAAC,CAAA"}
1
+ {"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../source/authenticate.ts"],"names":[],"mappings":";;;AAAA,6CAAiC;AACjC,+BAAwC;AAMjC,KAAK,UAAU,MAAM,CAAE,EAAE,M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AE,EAAE,MAAM,EAAE,EAAE,CAAA;AAClD,CAAC;AA/BD,wBA+BC;AAED,MAAM,aAAa,GAAG,IAAI,iBAAG,CAAC,WAAW,CAAC,CAAA"}
@@ -1,2 +1,3 @@
1
- import type { Context, IdToken } from './types';
2
- export declare const computation: (token: string, context: Context) => Promise<Error | Promise<IdToken>>;
1
+ import type { JWTPayload } from 'jose';
2
+ import type { Context } from './types';
3
+ export declare function effect(token: string, context: Context): Promise<JWTPayload | Error>;
@@ -1,33 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.computation = void 0;
27
- const jwt = __importStar(require("./lib/jwt"));
28
- const assertions_as_values_1 = require("./lib/assertions-as-values");
29
- async function decode(token, context) {
30
- return await jwt.decode(token, context.configuration.trust, context.stash);
3
+ exports.effect = void 0;
4
+ const lib_1 = require("./lib");
5
+ async function effect(token, context) {
6
+ return await (0, lib_1.decode)(token, {
7
+ trust: context.configuration.trust,
8
+ stash: context.stash,
9
+ logs: context.logs
10
+ });
31
11
  }
32
- exports.computation = (0, assertions_as_values_1.assertionsAsValues)(decode);
12
+ exports.effect = effect;
33
13
  //# sourceMappingURL=decode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decode.js","sourceRoot":"","sources":["../source/decode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,qEAA+D;AAG/D,KAAK,UAAU,MAAM,CAAE,KAAa,EAAE,OAAgB;IACpD,OAAO,MAAM,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;AAC5E,CAAC;AAEY,QAAA,WAAW,GAAG,IAAA,yCAAkB,EAAC,MAAM,CAAC,CAAA"}
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../source/decode.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAIvB,KAAK,UAAU,MAAM,CAAE,KAAa,EAAE,OAAgB;IAC3D,OAAO,MAAM,IAAA,YAAM,EAAC,KAAK,EAAE;QACzB,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC,CAAA;AACJ,CAAC;AAND,wBAMC"}
@@ -1,5 +1,7 @@
1
- import type { Context } from './types';
1
+ import type { Context, Scheme } from './types';
2
+ export declare function effect(input: Input, context: Context): Promise<Output | Error>;
2
3
  export interface Input {
4
+ scheme: Scheme;
3
5
  authority: string;
4
6
  credentials: string;
5
7
  id?: string;
@@ -7,4 +9,3 @@ export interface Input {
7
9
  export interface Output {
8
10
  id: string;
9
11
  }
10
- export declare const effect: (input: Input, context: Context) => Promise<Error | Promise<Output>>;
@@ -1,14 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.effect = void 0;
4
- const assertions_as_values_js_1 = require("./lib/assertions-as-values.js");
5
- const jwt_1 = require("./lib/jwt");
6
- async function incept(input, context) {
7
- const { iss, sub } = await (0, jwt_1.decode)(input.credentials, context.configuration.trust, context.stash);
4
+ const error_value_1 = require("error-value");
5
+ const lib_1 = require("./lib");
6
+ async function effect(input, context) {
7
+ if (input.scheme !== 'bearer')
8
+ return ERR_SCHEME;
9
+ const payload = await (0, lib_1.decode)(input.credentials, {
10
+ trust: context.configuration.trust,
11
+ stash: context.stash,
12
+ logs: context.logs
13
+ });
14
+ if (payload instanceof Error)
15
+ return payload;
16
+ const { iss, sub } = payload;
8
17
  const request = { input: { authority: input.authority, iss, sub } };
9
18
  if (input.id !== undefined)
10
19
  request.query = { id: input.id };
11
20
  return await context.local.transit(request);
12
21
  }
13
- exports.effect = (0, assertions_as_values_js_1.assertionsAsValues)(incept);
22
+ exports.effect = effect;
23
+ const ERR_SCHEME = new error_value_1.Err('ERR_SCHEME', 'Unsupported scheme');
14
24
  //# sourceMappingURL=incept.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"incept.js","sourceRoot":"","sources":["../source/incept.ts"],"names":[],"mappings":";;;AAAA,2EAAkE;AAClE,mCAAkC;AAIlC,KAAK,UAAU,MAAM,CAAE,KAAY,EAAE,OAAgB;IACnD,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,IAAA,YAAM,EAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAChG,MAAM,OAAO,GAA0B,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,EAA+B,EAAE,CAAA;IAEvH,IAAI,KAAK,CAAC,EAAE,KAAK,SAAS;QACxB,OAAO,CAAC,KAAK,GAAG,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAA;IAElC,OAAO,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAC7C,CAAC;AAYY,QAAA,MAAM,GAAG,IAAA,4CAAkB,EAAC,MAAM,CAAC,CAAA"}
1
+ {"version":3,"file":"incept.js","sourceRoot":"","sources":["../source/incept.ts"],"names":[],"mappings":";;;AAAA,6CAAiC;AACjC,+BAA8B;AAIvB,KAAK,UAAU,MAAM,CAAE,KAAY,EAAE,OAAgB;IAC1D,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAA;IAEhD,MAAM,OAAO,GAAG,MAAM,IAAA,YAAM,EAAC,KAAK,CAAC,WAAW,EAAE;QAC9C,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC,CAAA;IAEF,IAAI,OAAO,YAAY,KAAK;QAC1B,OAAO,OAAO,CAAA;IAEhB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,CAAA;IAC5B,MAAM,OAAO,GAA0B,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,EAA+B,EAAE,CAAA;IAEvH,IAAI,KAAK,CAAC,EAAE,KAAK,SAAS;QACxB,OAAO,CAAC,KAAK,GAAG,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAA;IAElC,OAAO,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAC7C,CAAC;AAnBD,wBAmBC;AAED,MAAM,UAAU,GAAG,IAAI,iBAAG,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAA"}
@@ -0,0 +1,39 @@
1
+ export interface Configuration extends Record<string, unknown> {
2
+ issuer: string;
3
+ authorization_endpoint: string;
4
+ token_endpoint: string;
5
+ userinfo_endpoint: string;
6
+ jwks_uri: string;
7
+ registration_endpoint?: string;
8
+ scopes_supported?: string[];
9
+ response_types_supported: string[];
10
+ response_modes_supported?: string[];
11
+ grant_types_supported?: string[];
12
+ acr_values_supported?: string[];
13
+ subject_types_supported: string[];
14
+ id_token_signing_alg_values_supported: string[];
15
+ id_token_encryption_alg_values_supported?: string[];
16
+ id_token_encryption_enc_values_supported?: string[];
17
+ userinfo_signing_alg_values_supported?: string[];
18
+ userinfo_encryption_alg_values_supported?: string[];
19
+ userinfo_encryption_enc_values_supported?: string[];
20
+ request_object_signing_alg_values_supported?: string[];
21
+ request_object_encryption_alg_values_supported?: string[];
22
+ request_object_encryption_enc_values_supported?: string[];
23
+ token_endpoint_auth_methods_supported?: string[];
24
+ token_endpoint_auth_signing_alg_values_supported?: string[];
25
+ display_values_supported?: string[];
26
+ claim_types_supported?: string[];
27
+ claims_supported?: string[];
28
+ service_documentation?: string;
29
+ claims_locales_supported?: string[];
30
+ ui_locales_supported?: string[];
31
+ claims_parameter_supported?: boolean;
32
+ request_parameter_supported?: boolean;
33
+ request_uri_parameter_supported?: boolean;
34
+ require_request_uri_registration?: boolean;
35
+ op_policy_uri?: string;
36
+ op_tos_uri?: string;
37
+ check_session_iframe?: string;
38
+ end_session_endpoint?: string;
39
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../source/lib/Configuration.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import type { Stash, telemetry } from '@toa.io/types';
2
+ import type { Trust } from '../types';
3
+ export interface Ctx {
4
+ trust: Trust[];
5
+ stash: Stash;
6
+ logs: telemetry.Logs;
7
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Ctx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ctx.js","sourceRoot":"","sources":["../../source/lib/Ctx.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type * as jose from 'jose';
2
+ export interface Payload extends jose.JWTPayload {
3
+ iss: string;
4
+ sub: string;
5
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Payload.js","sourceRoot":"","sources":["../../source/lib/Payload.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { Ctx } from './Ctx';
2
+ import type { Payload } from './Payload';
3
+ export declare function decode(token: string, ctx: Ctx): Promise<Payload | Error>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.decode = void 0;
27
+ const jose = __importStar(require("jose"));
28
+ const discovery_1 = require("./discovery");
29
+ const errors_1 = require("./errors");
30
+ const jwks = {};
31
+ async function decode(token, ctx) {
32
+ const { iss, sub } = jose.decodeJwt(token);
33
+ if (typeof iss !== 'string')
34
+ return errors_1.ERR_ISS;
35
+ if (typeof sub !== 'string')
36
+ return errors_1.ERR_SUB;
37
+ const trusted = ctx.trust.find((trust) => trust.iss === iss);
38
+ if (trusted === undefined)
39
+ return errors_1.ERR_TRUST;
40
+ jwks[iss] ??= await (0, discovery_1.createRemoteJWKSet)(iss);
41
+ const { payload } = await jose.jwtVerify(token, jwks[iss], { audience: trusted.aud });
42
+ if (payload.jti !== undefined) {
43
+ const error = await validateJti(payload, ctx.stash);
44
+ if (error instanceof Error)
45
+ return error;
46
+ }
47
+ return payload;
48
+ }
49
+ exports.decode = decode;
50
+ async function validateJti(payload, stash) {
51
+ if (payload.exp === undefined)
52
+ return errors_1.ERR_EXP;
53
+ const ttl = payload.exp - Math.floor(Date.now() / 1000);
54
+ const key = `identity:federation:jti:${payload.jti}`;
55
+ const ok = await stash.set(key, 1, 'EX', ttl, 'NX'); // set if not exists
56
+ if (ok === null)
57
+ return errors_1.ERR_REPLAY;
58
+ }
59
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../../source/lib/decode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAC5B,2CAAgD;AAChD,qCAA2E;AAK3E,MAAM,IAAI,GAAmE,EAAE,CAAA;AAExE,KAAK,UAAU,MAAM,CAAE,KAAa,EAAE,GAAQ;IACnD,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAE1C,IAAI,OAAO,GAAG,KAAK,QAAQ;QACzB,OAAO,gBAAO,CAAA;IAEhB,IAAI,OAAO,GAAG,KAAK,QAAQ;QACzB,OAAO,gBAAO,CAAA;IAEhB,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,CAAA;IAE5D,IAAI,OAAO,KAAK,SAAS;QACvB,OAAO,kBAAS,CAAA;IAElB,IAAI,CAAC,GAAG,CAAC,KAAK,MAAM,IAAA,8BAAkB,EAAC,GAAG,CAAC,CAAA;IAE3C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IAErF,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;QAEnD,IAAI,KAAK,YAAY,KAAK;YACxB,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,OAAO,OAAkB,CAAA;AAC3B,CAAC;AA1BD,wBA0BC;AAED,KAAK,UAAU,WAAW,CAAE,OAAwB,EAAE,KAAY;IAChE,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS;QAC3B,OAAO,gBAAO,CAAA;IAEhB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACvD,MAAM,GAAG,GAAG,2BAA2B,OAAO,CAAC,GAAG,EAAE,CAAA;IACpD,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA,CAAC,oBAAoB;IAExE,IAAI,EAAE,KAAK,IAAI;QACb,OAAO,mBAAU,CAAA;AACrB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import * as jose from 'jose';
2
+ import type { Configuration } from './Configuration';
3
+ export declare function discover(iss: string): Promise<Configuration>;
4
+ export declare function createRemoteJWKSet(iss: string): Promise<ReturnType<typeof jose.createRemoteJWKSet>>;
@@ -23,25 +23,27 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.assertionsAsValues = void 0;
27
- const assert = __importStar(require("node:assert"));
28
- const openspan_1 = require("openspan");
29
- /**
30
- * Wrapping function that returns assertion errors as function return value
31
- */
32
- function assertionsAsValues(fn) {
33
- return async (...args) => {
34
- try {
35
- return await fn(...args);
36
- }
37
- catch (err) {
38
- if (err instanceof assert.AssertionError) {
39
- openspan_1.console.error('OIDC Authentication exception', { message: err.message });
40
- return err;
41
- }
42
- throw err;
43
- }
44
- };
26
+ exports.createRemoteJWKSet = exports.discover = void 0;
27
+ const jose = __importStar(require("jose"));
28
+ const cache = new Map();
29
+ async function discover(iss) {
30
+ if (!cache.has(iss)) {
31
+ const configuration = await fetchConfiguration(iss);
32
+ cache.set(iss, configuration);
33
+ }
34
+ return cache.get(iss);
35
+ }
36
+ exports.discover = discover;
37
+ async function fetchConfiguration(iss) {
38
+ const response = await fetch(`${iss}/.well-known/openid-configuration`);
39
+ if (!response.ok)
40
+ throw new Error('Failed to fetch OIDC configuration');
41
+ return await response.json();
42
+ }
43
+ async function createRemoteJWKSet(iss) {
44
+ const configuration = await discover(iss);
45
+ const url = new URL(configuration.jwks_uri);
46
+ return jose.createRemoteJWKSet(url);
45
47
  }
46
- exports.assertionsAsValues = assertionsAsValues;
47
- //# sourceMappingURL=assertions-as-values.js.map
48
+ exports.createRemoteJWKSet = createRemoteJWKSet;
49
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../source/lib/discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAG5B,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAA;AAEvC,KAAK,UAAU,QAAQ,CAAE,GAAW;IACzC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,aAAa,GAAG,MAAM,kBAAkB,CAAC,GAAG,CAAC,CAAA;QAEnD,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;IAC/B,CAAC;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;AACxB,CAAC;AARD,4BAQC;AAED,KAAK,UAAU,kBAAkB,CAAE,GAAW;IAC5C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,mCAAmC,CAAC,CAAA;IAEvE,IAAI,CAAC,QAAQ,CAAC,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IAEvD,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAmB,CAAA;AAC/C,CAAC;AAEM,KAAK,UAAU,kBAAkB,CAAE,GAAW;IACnD,MAAM,aAAa,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAA;IACzC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;IAE3C,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAA;AACrC,CAAC;AALD,gDAKC"}
@@ -0,0 +1,11 @@
1
+ import { Err } from 'error-value';
2
+ export declare const ERR_TRUST: Err<"TRUST", any>;
3
+ export declare const ERR_RESPONSE: Err<"RESPONSE", any>;
4
+ export declare const ERR_CONFIG: Err<"CONFIG", any>;
5
+ export declare const ERR_NO_TOKEN: Err<"NO_TOKEN", any>;
6
+ export declare const ERR_ISS: Err<"ISS", any>;
7
+ export declare const ERR_SUB: Err<"SUB", any>;
8
+ export declare const ERR_EXP: Err<"EXP", any>;
9
+ export declare const ERR_REPLAY: Err<"REPLAY", any>;
10
+ export declare const ERR_CODE_NOT_ENABLED: Err<"CODE_NOT_ENABLED", any>;
11
+ export declare const ERR_CODE_SCHEMA: Err<"CODE_SCHEMA", any>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERR_CODE_SCHEMA = exports.ERR_CODE_NOT_ENABLED = exports.ERR_REPLAY = exports.ERR_EXP = exports.ERR_SUB = exports.ERR_ISS = exports.ERR_NO_TOKEN = exports.ERR_CONFIG = exports.ERR_RESPONSE = exports.ERR_TRUST = void 0;
4
+ const error_value_1 = require("error-value");
5
+ exports.ERR_TRUST = new error_value_1.Err('TRUST', 'Issuer not trusted');
6
+ exports.ERR_RESPONSE = new error_value_1.Err('RESPONSE', 'Request to IDP failed');
7
+ exports.ERR_CONFIG = new error_value_1.Err('CONFIG', 'Invalid OpenID configuration');
8
+ exports.ERR_NO_TOKEN = new error_value_1.Err('NO_TOKEN', 'No ID token received');
9
+ exports.ERR_ISS = new error_value_1.Err('ISS', 'Invalid issuer claim');
10
+ exports.ERR_SUB = new error_value_1.Err('SUB', 'Invalid subject claim');
11
+ exports.ERR_EXP = new error_value_1.Err('EXP', 'Token does not have an expiration time');
12
+ exports.ERR_REPLAY = new error_value_1.Err('REPLAY', 'Token has already been used');
13
+ exports.ERR_CODE_NOT_ENABLED = new error_value_1.Err('CODE_NOT_ENABLED', 'Authorization code flow is not configured');
14
+ exports.ERR_CODE_SCHEMA = new error_value_1.Err('CODE_SCHEMA', 'Invalid code credentials');
15
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../source/lib/errors.ts"],"names":[],"mappings":";;;AAAA,6CAAiC;AAEpB,QAAA,SAAS,GAAG,IAAI,iBAAG,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAA;AAClD,QAAA,YAAY,GAAG,IAAI,iBAAG,CAAC,UAAU,EAAE,uBAAuB,CAAC,CAAA;AAC3D,QAAA,UAAU,GAAG,IAAI,iBAAG,CAAC,QAAQ,EAAE,8BAA8B,CAAC,CAAA;AAC9D,QAAA,YAAY,GAAG,IAAI,iBAAG,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAA;AAC1D,QAAA,OAAO,GAAG,IAAI,iBAAG,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAA;AAChD,QAAA,OAAO,GAAG,IAAI,iBAAG,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAA;AACjD,QAAA,OAAO,GAAG,IAAI,iBAAG,CAAC,KAAK,EAAE,wCAAwC,CAAC,CAAA;AAClE,QAAA,UAAU,GAAG,IAAI,iBAAG,CAAC,QAAQ,EAAE,6BAA6B,CAAC,CAAA;AAC7D,QAAA,oBAAoB,GAAG,IAAI,iBAAG,CAAC,kBAAkB,EAAE,2CAA2C,CAAC,CAAA;AAC/F,QAAA,eAAe,GAAG,IAAI,iBAAG,CAAC,aAAa,EAAE,0BAA0B,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Ctx } from './Ctx';
2
+ import type { Payload } from './Payload';
3
+ export declare function exchange(credentials: string, ctx: Ctx): Promise<Payload | Error>;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.exchange = void 0;
27
+ const jose = __importStar(require("jose"));
28
+ const discovery_1 = require("./discovery");
29
+ const errors = __importStar(require("./errors"));
30
+ const jwks = {};
31
+ async function exchange(credentials, ctx) {
32
+ const properties = decode(credentials);
33
+ if (properties instanceof Error)
34
+ return properties;
35
+ const { code, iss, for: redirect } = properties;
36
+ const trusted = ctx.trust.find((trust) => trust.iss === iss);
37
+ if (trusted === undefined)
38
+ return errors.ERR_TRUST;
39
+ if (trusted.aud === undefined || (trusted.secret === undefined && trusted.signature === undefined))
40
+ return errors.ERR_CODE_NOT_ENABLED;
41
+ const configuration = await (0, discovery_1.discover)(iss);
42
+ if (configuration.token_endpoint === undefined)
43
+ return errors.ERR_CONFIG;
44
+ // array actually is not expected here, but it is a valid format
45
+ const aud = Array.isArray(trusted.aud) ? trusted.aud[0] : trusted.aud;
46
+ const secret = trusted.secret ?? await sign(trusted);
47
+ const params = new URLSearchParams();
48
+ params.append('grant_type', 'authorization_code');
49
+ params.append('code', code);
50
+ params.append('client_id', aud);
51
+ params.append('client_secret', secret);
52
+ params.append('redirect_uri', redirect);
53
+ ctx.logs.debug('Exchanging code', {
54
+ iss,
55
+ aud,
56
+ for: redirect,
57
+ auth: trusted.secret === undefined ? 'signature' : 'secret',
58
+ code
59
+ });
60
+ const response = await fetch(configuration.token_endpoint, {
61
+ method: 'POST',
62
+ headers: {
63
+ 'Content-Type': 'application/x-www-form-urlencoded'
64
+ },
65
+ body: params
66
+ });
67
+ if (!response.ok) {
68
+ ctx.logs.error('Code exchange failed', { status: response.status, text: await response.text() });
69
+ return errors.ERR_RESPONSE;
70
+ }
71
+ const tokens = await response.json();
72
+ if (tokens.id_token === undefined)
73
+ return errors.ERR_NO_TOKEN;
74
+ jwks[iss] ??= await (0, discovery_1.createRemoteJWKSet)(iss);
75
+ const { payload } = await jose.jwtVerify(tokens.id_token, jwks[iss], {
76
+ audience: trusted.aud,
77
+ issuer: iss
78
+ });
79
+ return payload;
80
+ }
81
+ exports.exchange = exchange;
82
+ function decode(credentials) {
83
+ const json = Buffer.from(credentials, 'base64').toString('utf8');
84
+ const properties = JSON.parse(json);
85
+ if (typeof properties.code !== 'string' ||
86
+ typeof properties.iss !== 'string' ||
87
+ typeof properties.for !== 'string' ||
88
+ Object.keys(properties).length !== CREDENTIAL_PROPERTIES.length)
89
+ return errors.ERR_CODE_SCHEMA;
90
+ return properties;
91
+ }
92
+ async function sign(trust) {
93
+ const signature = trust.signature;
94
+ const aud = Array.isArray(trust.aud) ? trust.aud[0] : trust.aud;
95
+ const now = Math.floor(Date.now() / 1000);
96
+ const key = await jose.importPKCS8(signature.key, 'ES256');
97
+ return await new jose.SignJWT({})
98
+ .setProtectedHeader({ alg: 'ES256', kid: signature.kid })
99
+ .setIssuedAt(now)
100
+ .setExpirationTime(now + 300)
101
+ .setIssuer(signature.iss)
102
+ .setSubject(aud)
103
+ .setAudience(trust.iss)
104
+ .sign(key);
105
+ }
106
+ const CREDENTIAL_PROPERTIES = ['for', 'iss', 'code'];
107
+ //# sourceMappingURL=exchange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../source/lib/exchange.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAC5B,2CAA0D;AAC1D,iDAAkC;AAKlC,MAAM,IAAI,GAAmE,EAAE,CAAA;AAExE,KAAK,UAAU,QAAQ,CAAE,WAAmB,EAAE,GAAQ;IAC3D,MAAM,UAAU,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;IAEtC,IAAI,UAAU,YAAY,KAAK;QAC7B,OAAO,UAAU,CAAA;IAEnB,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAA;I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