@fabrika/iam 0.9.0-dev.30 → 0.9.0-dev.32
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.
- package/package.json +10 -10
- package/src/signing.ts +13 -5
- package/src/tokens.ts +15 -8
- package/types/src/signing.d.ts +4 -4
- package/types/src/tokens.d.ts +5 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/iam",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.32",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/contember/fabrika-platform.git",
|
|
@@ -56,15 +56,15 @@
|
|
|
56
56
|
"prune:auth-log": "bun src/node/prune.ts"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@fabrika/app": "0.9.0-dev.
|
|
60
|
-
"@fabrika/auth": "0.9.0-dev.
|
|
61
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
62
|
-
"@fabrika/email": "0.9.0-dev.
|
|
63
|
-
"@fabrika/iam-contract": "0.9.0-dev.
|
|
64
|
-
"@fabrika/platform": "0.9.0-dev.
|
|
65
|
-
"@fabrika/platform-node": "0.9.0-dev.
|
|
66
|
-
"@fabrika/provider-cloudflare": "0.9.0-dev.
|
|
67
|
-
"@fabrika/proxy-core": "0.9.0-dev.
|
|
59
|
+
"@fabrika/app": "0.9.0-dev.32",
|
|
60
|
+
"@fabrika/auth": "0.9.0-dev.32",
|
|
61
|
+
"@fabrika/auth-core": "0.9.0-dev.32",
|
|
62
|
+
"@fabrika/email": "0.9.0-dev.32",
|
|
63
|
+
"@fabrika/iam-contract": "0.9.0-dev.32",
|
|
64
|
+
"@fabrika/platform": "0.9.0-dev.32",
|
|
65
|
+
"@fabrika/platform-node": "0.9.0-dev.32",
|
|
66
|
+
"@fabrika/provider-cloudflare": "0.9.0-dev.32",
|
|
67
|
+
"@fabrika/proxy-core": "0.9.0-dev.32",
|
|
68
68
|
"jose": "^5.9.0",
|
|
69
69
|
"zod": "^3.25.76"
|
|
70
70
|
}
|
package/src/signing.ts
CHANGED
|
@@ -12,7 +12,15 @@
|
|
|
12
12
|
* One Signer per isolate, memoised like the `JwtValidator` (jose imports the key once).
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
type AccessTokenClaims,
|
|
17
|
+
type AccessTokenPayload,
|
|
18
|
+
type Jwks,
|
|
19
|
+
parseAccessClaims,
|
|
20
|
+
type PublicJwk,
|
|
21
|
+
RESOURCE_ACCESS_TOKEN_TYP,
|
|
22
|
+
TOKEN_ALG,
|
|
23
|
+
} from '@fabrika/auth-core'
|
|
16
24
|
import {
|
|
17
25
|
calculateJwkThumbprint,
|
|
18
26
|
createLocalJWKSet,
|
|
@@ -43,15 +51,15 @@ export class Signer {
|
|
|
43
51
|
private constructor(private readonly keys: LoadedKey[]) {}
|
|
44
52
|
|
|
45
53
|
/**
|
|
46
|
-
* Sign
|
|
47
|
-
* picks the matching public JWK. The claims already carry `iss`/`aud`/`exp` (built in core).
|
|
54
|
+
* Sign an access token payload (`accessTokenPayload`) with the ACTIVE key. The `kid` goes in the protected header so
|
|
55
|
+
* the SDK picks the matching public JWK. The claims already carry `iss`/`aud`/`exp` (built in core).
|
|
48
56
|
*/
|
|
49
|
-
sign(
|
|
57
|
+
sign(payload: AccessTokenPayload): Promise<string> {
|
|
50
58
|
const active = this.keys[0]
|
|
51
59
|
if (!active) {
|
|
52
60
|
throw new Error('Signer has no keys')
|
|
53
61
|
}
|
|
54
|
-
return new SignJWT({ ...
|
|
62
|
+
return new SignJWT({ ...payload })
|
|
55
63
|
.setProtectedHeader({ alg: TOKEN_ALG, kid: active.kid })
|
|
56
64
|
.sign(active.key)
|
|
57
65
|
}
|
package/src/tokens.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
type PermissionEntry,
|
|
29
29
|
permits,
|
|
30
30
|
type Scope,
|
|
31
|
+
signAccessClaims,
|
|
31
32
|
type TokenPrincipalType,
|
|
32
33
|
} from '@fabrika/auth-core'
|
|
33
34
|
import { sessionUsable } from './auth'
|
|
@@ -120,6 +121,7 @@ export async function mintToken(services: Services, env: MintEnv, input: MintTok
|
|
|
120
121
|
// A terminal's own entries are its principal's grants, and end with them.
|
|
121
122
|
(onTerminal === null ? null : authorityDeadline(onTerminal.authority, onTerminal.additions, now)) ?? Number.POSITIVE_INFINITY,
|
|
122
123
|
)
|
|
124
|
+
const bound = await proxyMintedBound(services, input.app)
|
|
123
125
|
const token = await boundedToken(
|
|
124
126
|
signAccessToken(services, env, {
|
|
125
127
|
app: input.app,
|
|
@@ -132,8 +134,8 @@ export async function mintToken(services: Services, env: MintEnv, input: MintTok
|
|
|
132
134
|
permissions,
|
|
133
135
|
issuedAt: now,
|
|
134
136
|
expiresAt,
|
|
135
|
-
}),
|
|
136
|
-
{ app: input.app, subject: principal.id, bytes:
|
|
137
|
+
}, bound),
|
|
138
|
+
{ app: input.app, subject: principal.id, bytes: bound },
|
|
137
139
|
)
|
|
138
140
|
if (token === null) {
|
|
139
141
|
return refused('token_too_large', principal.id)
|
|
@@ -249,6 +251,7 @@ export async function mintFromKey(
|
|
|
249
251
|
cred.expires_at ?? Number.POSITIVE_INFINITY,
|
|
250
252
|
effective.expiresAt ?? Number.POSITIVE_INFINITY,
|
|
251
253
|
)
|
|
254
|
+
const bound = await proxyMintedBound(services, input.app)
|
|
252
255
|
const token = await boundedToken(
|
|
253
256
|
signAccessToken(services, env, {
|
|
254
257
|
app: input.app,
|
|
@@ -261,8 +264,8 @@ export async function mintFromKey(
|
|
|
261
264
|
...(effective.link === undefined ? {} : { link: effective.link }),
|
|
262
265
|
issuedAt: now,
|
|
263
266
|
expiresAt,
|
|
264
|
-
}),
|
|
265
|
-
{ app: input.app, subject: effective.subject, bytes:
|
|
267
|
+
}, bound),
|
|
268
|
+
{ app: input.app, subject: effective.subject, bytes: bound },
|
|
266
269
|
)
|
|
267
270
|
if (token === null) {
|
|
268
271
|
return { result: { ok: false, reason: 'token_too_large' }, principalId: cred.principal_id, credentialId: cred.id }
|
|
@@ -302,8 +305,8 @@ export async function mintFromWorkloadKey(services: Services, env: MintEnv, inpu
|
|
|
302
305
|
permissions: effective.permissions,
|
|
303
306
|
issuedAt: now,
|
|
304
307
|
expiresAt,
|
|
305
|
-
}),
|
|
306
|
-
{ app: input.app, subject: effective.subject },
|
|
308
|
+
}, MAX_ACCESS_TOKEN_BYTES),
|
|
309
|
+
{ app: input.app, subject: effective.subject, bytes: MAX_ACCESS_TOKEN_BYTES },
|
|
307
310
|
)
|
|
308
311
|
if (token === null) {
|
|
309
312
|
return refused
|
|
@@ -494,13 +497,17 @@ export async function boundedToken(
|
|
|
494
497
|
return null
|
|
495
498
|
}
|
|
496
499
|
|
|
497
|
-
/**
|
|
500
|
+
/**
|
|
501
|
+
* Sign an access token with the isolate's active signing key, in the compact layout only when the entries layout is
|
|
502
|
+
* above `bound` (`signAccessClaims`); `boundedToken` refuses one still above it. Shared by every mint front.
|
|
503
|
+
*/
|
|
498
504
|
export async function signAccessToken(
|
|
499
505
|
services: Services,
|
|
500
506
|
env: MintEnv,
|
|
501
507
|
params: Omit<Parameters<typeof buildAccessClaims>[0], 'iss'>,
|
|
508
|
+
bound: number,
|
|
502
509
|
): Promise<string> {
|
|
503
510
|
const signer = await getSigner(env)
|
|
504
511
|
const claims: AccessTokenClaims = buildAccessClaims({ ...params, iss: services.config.issuer })
|
|
505
|
-
return signer.sign(
|
|
512
|
+
return signAccessClaims(claims, bound, (payload) => signer.sign(payload))
|
|
506
513
|
}
|
package/types/src/signing.d.ts
CHANGED
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
*
|
|
12
12
|
* One Signer per isolate, memoised like the `JwtValidator` (jose imports the key once).
|
|
13
13
|
*/
|
|
14
|
-
import { type AccessTokenClaims, type Jwks } from '@fabrika/auth-core';
|
|
14
|
+
import { type AccessTokenClaims, type AccessTokenPayload, type Jwks } from '@fabrika/auth-core';
|
|
15
15
|
import { type JWK, type JWTPayload } from 'jose';
|
|
16
16
|
import type { Env } from './env';
|
|
17
17
|
export declare class Signer {
|
|
18
18
|
private readonly keys;
|
|
19
19
|
private constructor();
|
|
20
20
|
/**
|
|
21
|
-
* Sign
|
|
22
|
-
* picks the matching public JWK. The claims already carry `iss`/`aud`/`exp` (built in core).
|
|
21
|
+
* Sign an access token payload (`accessTokenPayload`) with the ACTIVE key. The `kid` goes in the protected header so
|
|
22
|
+
* the SDK picks the matching public JWK. The claims already carry `iss`/`aud`/`exp` (built in core).
|
|
23
23
|
*/
|
|
24
|
-
sign(
|
|
24
|
+
sign(payload: AccessTokenPayload): Promise<string>;
|
|
25
25
|
/**
|
|
26
26
|
* Sign an OAuth resource access token (`buildResourceAccessClaims`). `typ: at+jwt` (RFC 9068) is what
|
|
27
27
|
* keeps it from passing as a native app token, whose header carries no `typ`.
|
package/types/src/tokens.d.ts
CHANGED
|
@@ -108,6 +108,9 @@ export declare function boundedToken(signed: Promise<string>, who: {
|
|
|
108
108
|
subject: string;
|
|
109
109
|
bytes?: number;
|
|
110
110
|
}): Promise<string | null>;
|
|
111
|
-
/**
|
|
112
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Sign an access token with the isolate's active signing key, in the compact layout only when the entries layout is
|
|
113
|
+
* above `bound` (`signAccessClaims`); `boundedToken` refuses one still above it. Shared by every mint front.
|
|
114
|
+
*/
|
|
115
|
+
export declare function signAccessToken(services: Services, env: MintEnv, params: Omit<Parameters<typeof buildAccessClaims>[0], 'iss'>, bound: number): Promise<string>;
|
|
113
116
|
export {};
|