@toa.io/extensions.exposition 1.0.0-alpha.101 → 1.0.0-alpha.103

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 (90) hide show
  1. package/components/identity.basic/manifest.toa.yaml +9 -0
  2. package/components/identity.basic/operations/authenticate.js +2 -2
  3. package/components/identity.basic/operations/authenticate.js.map +1 -1
  4. package/components/identity.basic/operations/incept.js +1 -1
  5. package/components/identity.basic/operations/incept.js.map +1 -1
  6. package/components/identity.basic/operations/transit.js +3 -3
  7. package/components/identity.basic/operations/transit.js.map +1 -1
  8. package/components/identity.basic/operations/tsconfig.tsbuildinfo +1 -1
  9. package/components/identity.basic/source/authenticate.ts +2 -2
  10. package/components/identity.basic/source/incept.ts +1 -1
  11. package/components/identity.basic/source/transit.ts +3 -3
  12. package/components/identity.federation/operations/authenticate.js +1 -1
  13. package/components/identity.federation/operations/authenticate.js.map +1 -1
  14. package/components/identity.federation/operations/tsconfig.tsbuildinfo +1 -1
  15. package/components/identity.federation/source/authenticate.ts +1 -1
  16. package/components/identity.keys/manifest.toa.yaml +54 -0
  17. package/components/identity.keys/operations/create.d.ts +22 -0
  18. package/components/identity.keys/operations/create.js +16 -0
  19. package/components/identity.keys/operations/create.js.map +1 -0
  20. package/components/identity.keys/operations/tsconfig.tsbuildinfo +1 -0
  21. package/components/identity.keys/source/create.ts +35 -0
  22. package/components/identity.keys/tsconfig.json +9 -0
  23. package/components/identity.roles/manifest.toa.yaml +2 -0
  24. package/components/identity.roles/operations/grant.js +2 -2
  25. package/components/identity.roles/operations/grant.js.map +1 -1
  26. package/components/identity.roles/operations/tsconfig.tsbuildinfo +1 -1
  27. package/components/identity.roles/source/grant.ts +2 -2
  28. package/components/identity.tokens/manifest.toa.yaml +91 -11
  29. package/components/identity.tokens/operations/authenticate.d.ts +2 -2
  30. package/components/identity.tokens/operations/authenticate.js +12 -12
  31. package/components/identity.tokens/operations/authenticate.js.map +1 -1
  32. package/components/identity.tokens/operations/decrypt.d.ts +12 -3
  33. package/components/identity.tokens/operations/decrypt.js +62 -18
  34. package/components/identity.tokens/operations/decrypt.js.map +1 -1
  35. package/components/identity.tokens/operations/encrypt.d.ts +3 -3
  36. package/components/identity.tokens/operations/encrypt.js +24 -8
  37. package/components/identity.tokens/operations/encrypt.js.map +1 -1
  38. package/components/identity.tokens/operations/issue.d.ts +24 -0
  39. package/components/identity.tokens/operations/issue.js +58 -0
  40. package/components/identity.tokens/operations/issue.js.map +1 -0
  41. package/components/identity.tokens/operations/lib/index.d.ts +2 -0
  42. package/components/identity.tokens/operations/lib/index.js +19 -0
  43. package/components/identity.tokens/operations/lib/index.js.map +1 -0
  44. package/components/identity.tokens/operations/lib/pad.d.ts +1 -0
  45. package/components/identity.tokens/operations/lib/pad.js +5 -0
  46. package/components/identity.tokens/operations/lib/pad.js.map +1 -0
  47. package/components/identity.tokens/operations/{types.d.ts → lib/types.d.ts} +35 -7
  48. package/components/identity.tokens/operations/lib/types.js.map +1 -0
  49. package/components/identity.tokens/operations/revoke.d.ts +2 -2
  50. package/components/identity.tokens/operations/revoke.js.map +1 -1
  51. package/components/identity.tokens/operations/tsconfig.tsbuildinfo +1 -1
  52. package/components/identity.tokens/source/authenticate.test.ts +13 -7
  53. package/components/identity.tokens/source/authenticate.ts +14 -14
  54. package/components/identity.tokens/source/decrypt.test.ts +29 -16
  55. package/components/identity.tokens/source/decrypt.ts +90 -20
  56. package/components/identity.tokens/source/encrypt.test.ts +44 -13
  57. package/components/identity.tokens/source/encrypt.ts +36 -12
  58. package/components/identity.tokens/source/issue.ts +80 -0
  59. package/components/identity.tokens/source/lib/index.ts +2 -0
  60. package/components/identity.tokens/source/lib/pad.ts +1 -0
  61. package/components/identity.tokens/source/lib/paseto.test.ts +16 -0
  62. package/components/identity.tokens/source/{types.ts → lib/types.ts} +37 -7
  63. package/components/identity.tokens/source/revoke.ts +2 -2
  64. package/components/octets.storage/operations/put.js +4 -4
  65. package/documentation/components.md +77 -39
  66. package/features/identity.tokens.feature +0 -43
  67. package/features/identtiy.tokens.custom.feature +247 -0
  68. package/features/octets.cloudinary.feature +2 -2
  69. package/features/steps/Gateway.ts +3 -1
  70. package/package.json +7 -4
  71. package/source/directives/auth/Authorization.ts +30 -18
  72. package/source/directives/auth/Delegate.ts +1 -3
  73. package/source/directives/auth/Role.ts +4 -8
  74. package/source/directives/auth/types.ts +2 -1
  75. package/source/directives/octets/Put.ts +3 -19
  76. package/transpiled/directives/auth/Authorization.d.ts +2 -1
  77. package/transpiled/directives/auth/Authorization.js +25 -16
  78. package/transpiled/directives/auth/Authorization.js.map +1 -1
  79. package/transpiled/directives/auth/Delegate.js +1 -2
  80. package/transpiled/directives/auth/Delegate.js.map +1 -1
  81. package/transpiled/directives/auth/Role.d.ts +1 -1
  82. package/transpiled/directives/auth/Role.js +3 -5
  83. package/transpiled/directives/auth/Role.js.map +1 -1
  84. package/transpiled/directives/auth/types.d.ts +2 -1
  85. package/transpiled/directives/octets/Put.d.ts +0 -1
  86. package/transpiled/directives/octets/Put.js +0 -11
  87. package/transpiled/directives/octets/Put.js.map +1 -1
  88. package/transpiled/tsconfig.tsbuildinfo +1 -1
  89. package/components/identity.tokens/operations/types.js.map +0 -1
  90. /package/components/identity.tokens/operations/{types.js → lib/types.js} +0 -0
@@ -13,8 +13,26 @@ operations:
13
13
  identity*: &identity
14
14
  id: string
15
15
  ...: true
16
- lifetime: integer[0,) # seconds
17
- output: string
16
+ lifetime: &lifetime
17
+ type: number
18
+ minimum: 0
19
+ scopes: [string]
20
+ permissions:
21
+ ~: [string]
22
+ key:
23
+ type: object
24
+ properties:
25
+ id:
26
+ type: string
27
+ key:
28
+ type: string
29
+ required:
30
+ - id
31
+ - key
32
+ output:
33
+ type: string
34
+ errors:
35
+ - ERR_INACCESSIBLE_SCOPE
18
36
  decrypt:
19
37
  input: string
20
38
  output:
@@ -23,6 +41,10 @@ operations:
23
41
  iat: string
24
42
  exp: string
25
43
  refresh: boolean
44
+ errors:
45
+ - INVALID_TOKEN
46
+ - INVALID_KEY
47
+ - FORGED_KEY
26
48
  authenticate:
27
49
  input:
28
50
  authority*: string
@@ -30,6 +52,43 @@ operations:
30
52
  output:
31
53
  identity: *identity
32
54
  refresh: boolean
55
+ errors:
56
+ - AUTHORITY_MISMATCH
57
+ - TOKEN_REVOKED
58
+ issue:
59
+ input:
60
+ type: object
61
+ properties:
62
+ authority:
63
+ type: string
64
+ identity:
65
+ type: string
66
+ lifetime: *lifetime
67
+ scopes:
68
+ type: array
69
+ items:
70
+ type: string
71
+ permissions:
72
+ type: object
73
+ additionalProperties:
74
+ type: array
75
+ items:
76
+ type: string
77
+ label:
78
+ type: string
79
+ minLength: 1
80
+ maxLength: 64
81
+ required:
82
+ - authority
83
+ - identity
84
+ - lifetime
85
+ - label
86
+ output:
87
+ kid: string
88
+ exp: number
89
+ token: string
90
+ errors:
91
+ - ERR_INACCESSIBLE_SCOPE
33
92
  revoke:
34
93
  concurrency: retry
35
94
 
@@ -38,16 +97,37 @@ receivers:
38
97
  identity.bans.updated: revoke
39
98
 
40
99
  configuration:
41
- key0*: string
42
- key1: string
43
- lifetime: 2592000 # seconds, 30 days
44
- refresh: 600 # seconds, 10 minutes
100
+ keys:
101
+ type: object
102
+ minProperties: 1
103
+ additionalProperties:
104
+ type: string
105
+ lifetime:
106
+ description: Token expiration time in seconds (default 30 days)
107
+ type: number
108
+ default: 2592000
109
+ refresh:
110
+ description: Token refresh time in seconds (default 10 minutes)
111
+ type: number
112
+ default: 600
113
+ cache:
114
+ description: Custom token keys LRU cache configuration
115
+ properties:
116
+ max:
117
+ type: number
118
+ default: 1024
119
+ ttl:
120
+ type: number
121
+ default: 600_000
122
+ default: { }
123
+
45
124
 
46
125
  exposition:
47
- /:
126
+ /:identity:
127
+ auth:id: identity
128
+ auth:role: system:identity:tokens
48
129
  POST:
49
- auth:scheme: token
50
- auth:delegate: identity
51
- io:output: true # string
52
130
  map:authority: authority
53
- endpoint: encrypt
131
+ io:input: [authority, identity, lifetime, label, scopes, permissions]
132
+ io:output: [kid, exp, token, label]
133
+ endpoint: issue
@@ -1,5 +1,5 @@
1
- import { type Maybe, type Operation } from '@toa.io/types';
2
- import type { AuthenticateInput, AuthenticateOutput, Context } from './types';
1
+ import type { Maybe, Operation } from '@toa.io/types';
2
+ import type { AuthenticateInput, AuthenticateOutput, Context } from './lib';
3
3
  export declare class Computation implements Operation {
4
4
  private refresh;
5
5
  private decrypt;
@@ -4,29 +4,29 @@ exports.Computation = void 0;
4
4
  const error_value_1 = require("error-value");
5
5
  class Computation {
6
6
  refresh = 0;
7
- decrypt = undefined;
8
- observe = undefined;
7
+ decrypt;
8
+ observe;
9
9
  mount(context) {
10
10
  this.refresh = context.configuration.refresh * 1000;
11
11
  this.decrypt = context.local.decrypt;
12
12
  this.observe = context.local.observe;
13
13
  }
14
14
  async execute(input) {
15
- const claim = await this.decrypt({ input: input.credentials });
16
- if (claim instanceof Error)
17
- return claim;
18
- if (claim.authority !== input.authority)
15
+ const claims = await this.decrypt({ input: input.credentials });
16
+ if (claims instanceof Error)
17
+ return claims;
18
+ if (claims.iss !== input.authority)
19
19
  return ERR_AUTHORITY;
20
- const identity = claim.identity;
21
- const iat = new Date(claim.iat).getTime();
22
- const transient = claim.exp !== undefined;
20
+ const identity = claims.identity;
21
+ const iat = new Date(claims.iat).getTime();
22
+ const transient = claims.exp !== undefined;
23
23
  const stale = transient && (iat + this.refresh < Date.now());
24
24
  if (stale) {
25
25
  const revocation = await this.observe({ query: { id: identity.id } });
26
26
  if (revocation?.revokedAt !== undefined && iat < revocation.revokedAt)
27
27
  return ERR_TOKEN_REVOKED;
28
28
  }
29
- const refresh = stale || claim.refresh;
29
+ const refresh = stale || claims.refresh;
30
30
  return {
31
31
  identity,
32
32
  refresh
@@ -34,6 +34,6 @@ class Computation {
34
34
  }
35
35
  }
36
36
  exports.Computation = Computation;
37
- const ERR_AUTHORITY = (0, error_value_1.Err)('AUTHORITY_MISMATCH');
38
- const ERR_TOKEN_REVOKED = (0, error_value_1.Err)('TOKEN_REVOKED');
37
+ const ERR_AUTHORITY = new error_value_1.Err('AUTHORITY_MISMATCH');
38
+ const ERR_TOKEN_REVOKED = new error_value_1.Err('TOKEN_REVOKED');
39
39
  //# sourceMappingURL=authenticate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../source/authenticate.ts"],"names":[],"mappings":";;;AACA,6CAAiC;AAGjC,MAAa,WAAW;IACd,OAAO,GAAW,CAAC,CAAA;IACnB,OAAO,GAAgC,SAAmD,CAAA;IAC1F,OAAO,GAAgC,SAAmD,CAAA;IAE3F,KAAK,CAAE,OAAgB;QAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,OAAO,GAAG,IAAI,CAAA;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAA;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAA;IACtC,CAAC;IAEM,KAAK,CAAC,OAAO,CAAE,KAAwB;QAC5C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;QAE9D,IAAI,KAAK,YAAY,KAAK;YACxB,OAAO,KAAK,CAAA;QAEd,IAAI,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS;YACrC,OAAO,aAAa,CAAA;QAEtB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;QAC/B,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAA;QACzC,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,KAAK,SAAS,CAAA;QACzC,MAAM,KAAK,GAAG,SAAS,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAA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AChC,OAAO,aAAa,CAAA;QAEtB,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;QAChC,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAA;QAC1C,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,KAAK,SAAS,CAAA;QAC1C,MAAM,KAAK,GAAG,SAAS,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QAE5D,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;YAErE,IAAI,UAAU,EAAE,SAAS,KAAK,SAAS,IAAI,GAAG,GAAG,UAAU,CAAC,SAAS;gBACnE,OAAO,iBAAiB,CAAA;QAC5B,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,OAAO,CAAA;QAEvC,OAAO;YACL,QAAQ;YACR,OAAO;SACR,CAAA;IACH,CAAC;CACF;AAvCD,kCAuCC;AAED,MAAM,aAAa,GAAG,IAAI,iBAAG,CAAC,oBAAoB,CAAC,CAAA;AACnD,MAAM,iBAAiB,GAAG,IAAI,iBAAG,CAAC,eAAe,CAAC,CAAA"}
@@ -1,3 +1,12 @@
1
- import { type Maybe } from '@toa.io/types';
2
- import { type Context, type DecryptOutput } from './types';
3
- export declare function computation(token: string, context: Context): Promise<Maybe<DecryptOutput>>;
1
+ import type { Maybe, Operation } from '@toa.io/types';
2
+ import type { Context, DecryptOutput } from './lib';
3
+ export declare class Computation implements Operation {
4
+ private keys;
5
+ private cache;
6
+ private latest;
7
+ private remote;
8
+ mount(context: Context): void;
9
+ execute(token: string): Promise<Maybe<DecryptOutput>>;
10
+ private kid;
11
+ private key;
12
+ }
@@ -1,33 +1,77 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computation = void 0;
3
+ exports.Computation = void 0;
4
4
  const paseto_1 = require("paseto");
5
- async function computation(token, context) {
6
- let refresh = false;
7
- let claim = await decrypt(token, context.configuration.key0);
8
- if (claim === null && context.configuration.key1 !== undefined) {
9
- refresh = true;
10
- claim = await decrypt(token, context.configuration.key1);
5
+ const error_value_1 = require("error-value");
6
+ const lru_cache_1 = require("lru-cache");
7
+ class Computation {
8
+ keys = {};
9
+ cache;
10
+ latest;
11
+ remote;
12
+ mount(context) {
13
+ this.latest = Object.keys(context.configuration.keys)[0];
14
+ this.remote = context.remote.identity.keys;
15
+ this.cache = new lru_cache_1.LRUCache(context.configuration.cache);
16
+ for (const [kid, key] of Object.entries(context.configuration.keys))
17
+ this.keys[kid] = { key };
11
18
  }
12
- if (claim === null)
13
- return ERR_INVALID_TOKEN;
14
- else
19
+ async execute(token) {
20
+ const kid = this.kid(token);
21
+ if (kid instanceof Error)
22
+ return kid;
23
+ const key = await this.key(kid);
24
+ if (key instanceof Error)
25
+ return key;
26
+ const claims = await decrypt(token, key.key);
27
+ if (claims instanceof Error)
28
+ return claims;
29
+ if (key.identity !== undefined && claims.identity.id !== key.identity)
30
+ return ERR_FORGED_KEY;
15
31
  return {
16
- authority: claim.aud,
17
- identity: claim.identity,
18
- iat: claim.iat,
19
- exp: claim.exp,
20
- refresh
32
+ iss: claims.iss,
33
+ iat: claims.iat,
34
+ exp: claims.exp,
35
+ identity: claims.identity,
36
+ refresh: kid !== this.latest && key.identity === undefined
21
37
  };
38
+ }
39
+ kid(token) {
40
+ const [, , , footer] = token.split('.');
41
+ if (footer === undefined)
42
+ return ERR_INVALID_TOKEN;
43
+ try {
44
+ const json = Buffer.from(footer, 'base64url').toString('utf-8');
45
+ const { kid } = JSON.parse(json);
46
+ if (typeof kid !== 'string')
47
+ return ERR_INVALID_TOKEN;
48
+ return kid;
49
+ }
50
+ catch {
51
+ return ERR_INVALID_TOKEN;
52
+ }
53
+ }
54
+ async key(kid) {
55
+ if (kid in this.keys)
56
+ return this.keys[kid];
57
+ if (!this.cache.has(kid)) {
58
+ const value = await this.remote.observe({ query: { id: kid } });
59
+ this.cache.set(kid, { value });
60
+ }
61
+ const entry = this.cache.get(kid);
62
+ return entry?.value ?? ERR_INVALID_KEY;
63
+ }
22
64
  }
23
- exports.computation = computation;
65
+ exports.Computation = Computation;
24
66
  async function decrypt(token, key) {
25
67
  try {
26
68
  return await paseto_1.V3.decrypt(token, key);
27
69
  }
28
70
  catch {
29
- return null;
71
+ return ERR_INVALID_TOKEN;
30
72
  }
31
73
  }
32
- const ERR_INVALID_TOKEN = new Error('INVALID_TOKEN');
74
+ const ERR_INVALID_TOKEN = new error_value_1.Err('INVALID_TOKEN');
75
+ const ERR_INVALID_KEY = new error_value_1.Err('INVALID_KEY');
76
+ const ERR_FORGED_KEY = new error_value_1.Err('FORGED_KEY');
33
77
  //# sourceMappingURL=decrypt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../source/decrypt.ts"],"names":[],"mappings":";;;AAAA,mCAA2B;AAIpB,KAAK,UAAU,WAAW,CAAE,KAAa,EAAE,OAAgB;IAChE,IAAI,OAAO,GAAG,KAAK,CAAA;IACnB,IAAI,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;IAE5D,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC/D,OAAO,GAAG,IAAI,CAAA;QACd,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;IAC1D,CAAC;IAED,IAAI,KAAK,KAAK,IAAI;QAChB,OAAO,iBAAiB,CAAA;;QAExB,OAAO;YACL,SAAS,EAAE,KAAK,CAAC,GAAG;YACpB,Q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AAG,CAAA;QACZ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,iBAAiB,CAAA;QAC1B,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,GAAG,CAAE,GAAW;QAC5B,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI;YAClB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEvB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;YAE/D,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAChC,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEjC,OAAO,KAAK,EAAE,KAAK,IAAI,eAAe,CAAA;IACxC,CAAC;CACF;AA5ED,kCA4EC;AAED,KAAK,UAAU,OAAO,CAAE,KAAa,EAAE,GAAW;IAChD,IAAI,CAAC;QACH,OAAO,MAAM,WAAE,CAAC,OAAO,CAAS,KAAK,EAAE,GAAG,CAAC,CAAA;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,iBAAiB,CAAA;IAC1B,CAAC;AACH,CAAC;AAWD,MAAM,iBAAiB,GAAG,IAAI,iBAAG,CAAC,eAAe,CAAC,CAAA;AAClD,MAAM,eAAe,GAAG,IAAI,iBAAG,CAAC,aAAa,CAAC,CAAA;AAC9C,MAAM,cAAc,GAAG,IAAI,iBAAG,CAAC,YAAY,CAAC,CAAA"}
@@ -1,8 +1,8 @@
1
- import { type Operation } from '@toa.io/types';
2
- import { type Context, type EncryptInput } from './types';
1
+ import type { Operation, Maybe } from '@toa.io/types';
2
+ import type { Context, EncryptInput } from './lib';
3
3
  export declare class Effect implements Operation {
4
4
  private key;
5
5
  private lifetime;
6
6
  mount(context: Context): void;
7
- execute(input: EncryptInput): Promise<string>;
7
+ execute(input: EncryptInput): Promise<Maybe<string>>;
8
8
  }
@@ -2,25 +2,41 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Effect = void 0;
4
4
  const paseto_1 = require("paseto");
5
+ const error_value_1 = require("error-value");
5
6
  class Effect {
6
- key = '';
7
- lifetime = 0;
7
+ key;
8
+ lifetime;
8
9
  mount(context) {
9
- this.key = context.configuration.key0;
10
+ const [id, secret] = Object.entries(context.configuration.keys)[0];
11
+ this.key = { id, key: secret };
10
12
  this.lifetime = context.configuration.lifetime * 1000;
11
13
  }
12
14
  async execute(input) {
13
- const lifetime = input.lifetime === undefined ? this.lifetime : input.lifetime * 1000;
15
+ if (input.scopes?.some((scope) => !within(scope, input.identity.roles)) === true)
16
+ return ERR_INACCESSIBLE_SCOPE;
17
+ const lifetime = input.lifetime === undefined ? this.lifetime : (input.lifetime * 1000);
14
18
  const exp = lifetime === 0
15
19
  ? undefined
16
20
  : new Date(Date.now() + lifetime).toISOString();
21
+ const identity = {
22
+ id: input.identity.id,
23
+ roles: input.scopes ?? input.identity.roles
24
+ };
25
+ if (input.permissions !== undefined)
26
+ identity.permissions = input.permissions;
17
27
  const payload = {
18
- identity: input.identity,
19
- aud: input.authority,
20
- exp
28
+ identity,
29
+ iss: input.authority
21
30
  };
22
- return await paseto_1.V3.encrypt(payload, this.key);
31
+ if (exp !== undefined)
32
+ payload.exp = exp;
33
+ const key = input.key ?? this.key;
34
+ return await paseto_1.V3.encrypt(payload, key.key, { footer: { kid: key.id } });
23
35
  }
24
36
  }
25
37
  exports.Effect = Effect;
38
+ function within(scope, roles) {
39
+ return roles.some((role) => role === scope || scope.startsWith(role + ':'));
40
+ }
41
+ const ERR_INACCESSIBLE_SCOPE = new error_value_1.Err('INACCESSIBLE_SCOPE');
26
42
  //# sourceMappingURL=encrypt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../source/encrypt.ts"],"names":[],"mappings":";;;AAAA,mCAA2B;AAI3B,MAAa,MAAM;IACT,GAAG,GAAW,EAAE,CAAA;IAChB,QAAQ,GAAW,CAAC,CAAA;IAErB,KAAK,CAAE,OAAgB;QAC5B,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAA;QACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAA;IACvD,CAAC;IAEM,KAAK,CAAC,OAAO,CAAE,KAAmB;QACvC,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAA;QAErF,MAAM,GAAG,GAAG,QAAQ,KAAK,CAAC;YACxB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAA;QAEjD,MAAM,OAAO,GAAmB;YAC9B,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,GAAG,EAAE,KAAK,CAAC,SAAS;YACpB,GAAG;SACJ,CAAA;QAED,OAAO,MAAM,WAAE,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IAC5C,CAAC;CACF;AAxBD,wBAwBC"}
1
+ {"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../source/encrypt.ts"],"names":[],"mappings":";;;AAAA,mCAA2B;AAC3B,6CAAiC;AAIjC,MAAa,MAAM;IACT,GAAG,CAA0B;IAC7B,QAAQ,CAAS;IAElB,KAAK,CAAE,OAAgB;QAC5B,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC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CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAA;QAEjC,OAAO,MAAM,WAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;IACxE,CAAC;CACF;AAzCD,wBAyCC;AAED,SAAS,MAAM,CAAE,KAAa,EAAE,KAAe;IAC7C,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAA;AAC7E,CAAC;AAED,MAAM,sBAAsB,GAAG,IAAI,iBAAG,CAAC,oBAAoB,CAAC,CAAA"}
@@ -0,0 +1,24 @@
1
+ import type { Maybe, Operation } from '@toa.io/types';
2
+ import type { Context } from './lib';
3
+ export declare class Effect implements Operation {
4
+ private keys;
5
+ private roles;
6
+ private encrypt;
7
+ private lifetime;
8
+ mount(context: Context): void;
9
+ execute(input: Input): Promise<Maybe<Output>>;
10
+ }
11
+ interface Input {
12
+ authority: string;
13
+ identity: string;
14
+ lifetime: number;
15
+ label: string;
16
+ scopes?: string[];
17
+ permissions?: Record<string, string[]>;
18
+ }
19
+ interface Output {
20
+ kid: string;
21
+ exp?: number;
22
+ token: string;
23
+ }
24
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Effect = void 0;
4
+ class Effect {
5
+ keys;
6
+ roles;
7
+ encrypt;
8
+ lifetime;
9
+ mount(context) {
10
+ this.keys = context.remote.identity.keys;
11
+ this.roles = context.remote.identity.roles;
12
+ this.encrypt = context.local.encrypt;
13
+ this.lifetime = context.configuration.lifetime * 1000;
14
+ }
15
+ async execute(input) {
16
+ const expires = input.lifetime === 0
17
+ ? undefined
18
+ : new Date(Date.now() + input.lifetime * 1000).getTime();
19
+ const key = await this.keys.create({
20
+ input: {
21
+ identity: input.identity,
22
+ label: input.label,
23
+ expires
24
+ }
25
+ });
26
+ const roles = await this.roles.list({
27
+ query: {
28
+ criteria: `identity==${input.identity}`,
29
+ limit: 1024
30
+ }
31
+ });
32
+ const identity = {
33
+ id: input.identity,
34
+ roles
35
+ };
36
+ const { authority, lifetime, scopes, permissions } = input;
37
+ const token = await this.encrypt({
38
+ input: {
39
+ authority,
40
+ identity,
41
+ lifetime,
42
+ scopes,
43
+ permissions,
44
+ key
45
+ }
46
+ });
47
+ if (token instanceof Error)
48
+ return token;
49
+ return {
50
+ kid: key.id,
51
+ // technically, the token expires some time later
52
+ ...(expires !== undefined && { exp: expires }),
53
+ token
54
+ };
55
+ }
56
+ }
57
+ exports.Effect = Effect;
58
+ //# sourceMappingURL=issue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issue.js","sourceRoot":"","sources":["../source/issue.ts"],"names":[],"mappings":";;;AAGA,MAAa,MAAM;IACT,IAAI,CAAwC;IAC5C,KAAK,CAAyC;IAC9C,OAAO,CAA8B;IACrC,QAAQ,CAAS;IAElB,KAAK,CAAE,OAAgB;QAC5B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;QACxC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAA;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAA;QACpC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAA;IACvD,CAAC;IAEM,KAAK,CAAC,OAAO,CAAE,KAAY;QAChC,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,KAAK,CAAC;YAClC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,OAAO,EAAE,CAAA;QAE1D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;YACjC,KAAK,EAAE;gBACL,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,OAAO;aACR;SACF,CAAC,CAAA;QAEF,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YAClC,KAAK,EAAE;gBACL,QAAQ,EAAE,aAAa,KAAK,CAAC,QAAQ,EAAE;gBACvC,KAAK,EAAE,IAAI;aACZ;SACF,CAAC,CAAA;QAEF,MAAM,QAAQ,GAAa;YACzB,EAAE,EAAE,KAAK,CAAC,QAAQ;YAClB,KAAK;SACN,CAAA;QAED,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,KAAK,CAAA;QAE1D,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC/B,KAAK,EAAE;gBACL,SAAS;gBACT,QAAQ;gBACR,QAAQ;gBACR,MAAM;gBACN,WAAW;gBACX,GAAG;aACJ;SACF,CAAC,CAAA;QAEF,IAAI,KAAK,YAAY,KAAK;YACxB,OAAO,KAAK,CAAA;QAEd,OAAO;YACL,GAAG,EAAE,GAAG,CAAC,EAAE;YACX,iDAAiD;YACjD,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;YAC9C,KAAK;SACN,CAAA;IACH,CAAC;CACF;AA7DD,wBA6DC"}
@@ -0,0 +1,2 @@
1
+ export * from './pad';
2
+ export * from './types';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./pad"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,0CAAuB"}
@@ -0,0 +1 @@
1
+ export declare const PAD = "v3.local.";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PAD = void 0;
4
+ exports.PAD = 'v3.local.';
5
+ //# sourceMappingURL=pad.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pad.js","sourceRoot":"","sources":["../../source/lib/pad.ts"],"names":[],"mappings":";;;AAAa,QAAA,GAAG,GAAG,WAAW,CAAA"}
@@ -1,22 +1,39 @@
1
- import { type Call, type Maybe, type Observation } from '@toa.io/types';
1
+ import type { Call, Maybe, Observation } from '@toa.io/types';
2
2
  export interface Context {
3
3
  local: {
4
4
  observe: Observation<Entity>;
5
+ encrypt: Call<Maybe<string>, EncryptInput>;
5
6
  decrypt: Call<Maybe<DecryptOutput>, string>;
6
7
  };
8
+ remote: {
9
+ identity: {
10
+ keys: {
11
+ observe: Observation<CustomKey>;
12
+ create: Call<Key>;
13
+ };
14
+ roles: {
15
+ list: Call<string[]>;
16
+ };
17
+ };
18
+ };
7
19
  configuration: Configuration;
8
20
  }
9
21
  export interface Configuration {
10
- readonly key0: string;
11
- readonly key1?: string;
22
+ readonly keys: Record<string, string>;
12
23
  readonly lifetime: number;
13
24
  readonly refresh: number;
25
+ readonly cache: {
26
+ max: number;
27
+ ttl: number;
28
+ };
14
29
  }
15
30
  export interface Entity {
16
31
  revokedAt?: number;
17
32
  }
18
33
  export interface Identity extends Record<string, any> {
19
34
  id: string;
35
+ roles: string[];
36
+ permissions?: Record<string, string[]>;
20
37
  }
21
38
  export interface AuthenticateInput {
22
39
  authority: string;
@@ -30,17 +47,28 @@ export interface EncryptInput {
30
47
  authority: string;
31
48
  identity: Identity;
32
49
  lifetime?: number;
50
+ scopes?: string[];
51
+ permissions?: Record<string, string[]>;
52
+ key?: Key;
33
53
  }
34
54
  export interface DecryptOutput {
35
- authority: string;
36
- identity: Identity;
55
+ iss: string;
37
56
  iat: string;
38
57
  exp?: string;
58
+ identity: Identity;
39
59
  refresh: boolean;
40
60
  }
41
- export interface Claim {
61
+ export interface Claims {
42
62
  identity: Identity;
43
- aud: string;
63
+ iss: string;
44
64
  iat: string;
45
65
  exp?: string;
46
66
  }
67
+ export interface Key {
68
+ id: string;
69
+ key: string;
70
+ label: string;
71
+ }
72
+ export interface CustomKey extends Key {
73
+ identity: string;
74
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../source/lib/types.ts"],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
- import { type Entity } from './types';
2
- export declare function transition(_: never, object: Entity): void;
1
+ import type { Entity } from './lib';
2
+ export declare function transition(_: unknown, object: Entity): void;
@@ -1 +1 @@
1
- {"version":3,"file":"revoke.js","sourceRoot":"","sources":["../source/revoke.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CAAE,CAAQ,EAAE,MAAc;IAClD,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;AAC/B,CAAC;AAFD,gCAEC"}
1
+ {"version":3,"file":"revoke.js","sourceRoot":"","sources":["../source/revoke.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CAAE,CAAU,EAAE,MAAc;IACpD,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;AAC/B,CAAC;AAFD,gCAEC"}